Back to Lo

It Take

docs/data/it-take.md

1.53.0258 B
Original Source

Takes the first n elements from a sequence.

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