Files
lo/docs/data/core-takewhile.md
T
Samuel Berthe fa095e4b4f fix(doc): fix go playground demo URL (#832)
* fix(doc): fix go playground demo URL

* fix(doc): add more go playground demo URL
2026-03-06 00:09:59 +01:00

791 B

name, slug, sourceRef, category, subCategory, variantHelpers, playUrl, similarHelpers, position, signatures
name slug sourceRef category subCategory variantHelpers playUrl similarHelpers position signatures
TakeWhile takewhile slice.go#L605 core slice
core#slice#takewhile
https://go.dev/play/p/NJkLGvyRWm4
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"}