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.
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:
|
|
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: