Back to Lo

It Compact

docs/data/it-compact.md

1.53.0335 B
Original Source

Compact returns a sequence of all non-zero elements.

go
collection := func(yield func(int) bool) {
    yield(0)
    yield(1)
    yield(0)
    yield(2)
    yield(3)
    yield(0)
}

compacted := it.Compact(collection)
var result []int
for item := range compacted {
    result = append(result, item)
}
// result contains [1, 2, 3]