Files
lo/docs/data/core-takewhile.md
T
Yuliya c1d11cb658 Add iterator slice helpers (#791)
* add iterator slice helpers and channel dedup/tee

* note unbounded memory growth in Distinct; simplify Take

* avoid extra iteration in Take/TakeWhile/TakeFilter and precompute Sliding step

* avoid reallocations in Sliding overlap shift

* sliding uses ring buffer

* refactor Sliding and expand TestSliding

* Remove Tee; add TakeFilter variant, rewrite Sliding

* remove channel Distinct/DistinctBy

* TakeFilter/TakeFilterI for slice

* Revert "TakeFilter/TakeFilterI for slice"

This reverts commit 6d2fcdc07b.

* doc  add new helpers to llms.txt

---------

Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
2026-02-23 20:27:51 +01:00

748 B

name, slug, sourceRef, category, subCategory, variantHelpers, similarHelpers, position, signatures
name slug sourceRef category subCategory variantHelpers similarHelpers position signatures
TakeWhile takewhile slice.go#L605 core slice
core#slice#takewhile
core#slice#take
core#slice#dropwhile
core#slice#droprightwhile
core#slice#filter
core#slice#takefilter
core#slice#first
it#sequence#takewhile
195
func TakeWhile[T any, Slice ~[]T](collection Slice, predicate func(item T) bool) Slice

Takes elements from the beginning while the predicate returns true.

lo.TakeWhile([]int{0, 1, 2, 3, 4, 5}, func(val int) bool {
    return val < 3
})
// []int{0, 1, 2}

lo.TakeWhile([]string{"a", "aa", "aaa", "aa"}, func(val string) bool {
    return len(val) <= 2
})
// []string{"a", "aa"}