underscore/dropwhile.go
Ruidy b35a87e50c
feat: add TakeWhile and DropWhile functions (#42)
- Add TakeWhile: returns elements while predicate is true
- Add DropWhile: drops elements while predicate is true
- Comprehensive tests including edge cases
- Benchmarks included

Resolves Issue 14

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-16 08:51:51 +01:00

15 lines
483 B
Go

package underscore
// DropWhile drops elements from the beginning of the slice while the predicate returns true.
// It returns the remaining elements starting from the first element where the predicate returns false.
func DropWhile[T any](values []T, predicate func(T) bool) []T {
for i, v := range values {
if !predicate(v) {
res := make([]T, len(values)-i)
copy(res, values[i:])
return res
}
}
// All elements satisfy predicate, return empty slice
return []T{}
}