mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
974 B
974 B
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Count / CountBy | count | it/seq.go#L630 | it | sequence |
|
https://go.dev/play/p/1SmFJ5-zr |
|
|
110 |
Counts elements in a collection. Count counts elements equal to a value, CountBy counts elements matching a predicate.
Examples:
seq := func(yield func(int) bool) {
_ = yield(1)
_ = yield(2)
_ = yield(2)
_ = yield(3)
_ = yield(2)
}
cnt := it.Count(seq, 2)
// cnt == 3
seq := func(yield func(string) bool) {
_ = yield("apple")
_ = yield("banana")
_ = yield("apricot")
}
cnt := it.CountBy(seq, func(s string) bool {
return len(s) > 5
})
// cnt == 2 (banana, apricot)