mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
604 B
604 B
name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | variantHelpers | similarHelpers | position | |||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Compact | compact | it/seq.go#L699 | it | slice |
|
|
|
192 |
Compact returns a sequence of all non-zero elements.
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]