Today I encountered a case where I wanted to take the first n elements from a slice.
With the slice[low:high] notation you have to first check, whether the slice has n elements, which makes this simple operation rather long.
thingsToTake := 7
if len(things) > thingsToTake {
things = things[0:thingsToTake]
}
Do you think, such a feature would be appropriate for gen?
It’s certainly a convenient method, I use it in LINQ a lot. Will think about it – on the one hand, it’s handy. On the other, it’s very nearly covered by normal slice operations, so it feels like sugar.
Today I encountered a case where I wanted to take the first n elements from a slice. With the slice[low:high] notation you have to first check, whether the slice has n elements, which makes this simple operation rather long.
Do you think, such a feature would be appropriate for
gen
?