Back to Lo

Core Takewhile

docs/data/core-takewhile.md

1.53.0300 B
Original Source

Takes elements from the beginning while the predicate returns true.

go
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"}