Back to Lo

It Takewhile

docs/data/it-takewhile.md

1.53.0337 B
Original Source

Takes elements from the beginning of a sequence while the predicate returns true.

go
seq := func(yield func(int) bool) {
    yield(1)
    yield(2)
    yield(3)
    yield(4)
}
result := it.TakeWhile(seq, func(x int) bool {
    return x < 3
})
var out []int
for v := range result {
    out = append(out, v)
}
// out contains [1, 2]