Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take first n elements #70

Open
tp opened this issue Sep 23, 2014 · 1 comment
Open

Take first n elements #70

tp opened this issue Sep 23, 2014 · 1 comment

Comments

@tp
Copy link

tp commented Sep 23, 2014

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?

@clipperhouse
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants