Files
lo/docs/data/it-count.md
T
Samuel Berthe fa095e4b4f fix(doc): fix go playground demo URL (#832)
* fix(doc): fix go playground demo URL

* fix(doc): add more go playground demo URL
2026-03-06 00:09:59 +01:00

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
func Count[T comparable](collection iter.Seq[T], value T) int
func CountBy[T any](collection iter.Seq[T], predicate func(item T) bool) int
https://go.dev/play/p/UcJ-6cANwfY
it#sequence#count
it#sequence#countby
core#slice#count
it#sequence#countvalues
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)