-
-
Notifications
You must be signed in to change notification settings - Fork 935
feat: add Take, TakeWhile, FilterTake, Window, and Sliding functions #760
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: add Take, TakeWhile, FilterTake, Window, and Sliding functions #760
Conversation
Add five new slice manipulation functions with tests, examples, and documentation.
samber
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this first contribution.
Please add the description of the helper to the README. The documentation website is still young. I'm going to remove this legacy doc as soon as the SEO improves.
I suppose we can create similar helpers in subpackages and especially it, but we can do it in a follow-up PR.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #760 +/- ##
=======================================
Coverage 94.04% 94.05%
=======================================
Files 18 18
Lines 2840 2894 +54
=======================================
+ Hits 2671 2722 +51
- Misses 152 154 +2
- Partials 17 18 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except 1 comment, it seems good to me.
Do you plan to add more things on this PR ? Would you like to remove the draft tag ?
Edit: Please fix the linter error
|
Please note that some of your helpers are already implemented in https://github.com/samber/ro, with a streaming paradigm. |
Add five new slice manipulation functions with tests, examples, and documentation.
New Functions
Take
Safely takes the first n elements from a slice. Handles edge cases and creates a copy to avoid mutating the original.
Production use cases:
TakeWhile
Takes elements from the beginning while the predicate returns true. Useful for processing ordered data until a condition is met.
Production use cases:
FilterTake
Filters elements and takes the first n matches. More efficient than chaining Filter and Take, as it stops after finding n matches.
Production use cases:
Window
Creates overlapping sliding windows of a given size (step=1). Each window overlaps with the previous one by size-1 elements.
Production use cases:
Sliding
Creates sliding windows with configurable step size. More flexible than Window - can create overlapping or non-overlapping windows.
Production use cases: