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

feat: generic slice 'take' function #9

Merged
merged 1 commit into from
Jul 7, 2023
Merged

feat: generic slice 'take' function #9

merged 1 commit into from
Jul 7, 2023

Conversation

meowgorithm
Copy link
Member

Take returns a sub-slice containing at most N items from the head of a slice. I know Go’s not tail-call optimized, but I can still see this being handy.

Take returns a sub-slice containing at most N items from the head of a slice.
@meowgorithm meowgorithm requested a review from caarlos0 July 7, 2023 15:16
@maaslalani
Copy link
Member

maaslalani commented Jul 7, 2023

I wonder if calling this Head makes sense, which would allow us to also introduce Tail to "take" the last N elements of an array?

Another name pairing could be First and Last.

@meowgorithm
Copy link
Member Author

I think Head and Tail make a lot of logical sense, though in FP head usually returns a single element and tail returns a list of everything except the first item, so I'd be concerned about confusion there. Take is also a known FP term for getting the first N items.

Perhaps TakeHead could be an alias for Take and then TakeTail could take N item from the end.

@maaslalani
Copy link
Member

Take is also a known FP term for getting the first N items.

Ah, cool. I didn't know about this. Then this makes sense to me for sure!

@meowgorithm meowgorithm merged commit 50fb4f4 into main Jul 7, 2023
16 checks passed
@meowgorithm meowgorithm deleted the take branch July 7, 2023 17:49
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

Successfully merging this pull request may close these issues.

None yet

3 participants