Files
lo/docs/data/it-count.md
T

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/1SmFJ5-zr
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)