mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
fa095e4b4f
* fix(doc): fix go playground demo URL * fix(doc): add more go playground demo URL
1.0 KiB
1.0 KiB
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| TakeFilter | takefilter | it/seq.go#L725 | it | sequence |
|
https://go.dev/play/p/Db68Bhu4MCA |
|
|
130 |
Filters elements and takes the first n matches. Stops once n matches are found.
TakeFilter
seq := func(yield func(int) bool) {
yield(1)
yield(2)
yield(3)
yield(4)
yield(5)
yield(6)
}
result := it.TakeFilter(seq, 2, func(x int) bool {
return x%2 == 0
})
var out []int
for v := range result {
out = append(out, v)
}
// out contains [2, 4]
TakeFilterI
result := it.TakeFilterI(seq, 2, func(x, index int) bool {
return x%2 == 0 && index < 4
})
// out contains [2, 4]