mirror of
https://github.com/samber/lo.git
synced 2026-04-22 15:37:14 +08:00
fa095e4b4f
* fix(doc): fix go playground demo URL * fix(doc): add more go playground demo URL
30 lines
641 B
Markdown
30 lines
641 B
Markdown
---
|
|
name: CountValues
|
|
slug: countvalues
|
|
sourceRef: it/seq.go#L720
|
|
category: it
|
|
subCategory: slice
|
|
signatures:
|
|
- "func CountValues[T comparable](collection iter.Seq[T]) map[T]int"
|
|
playUrl: https://go.dev/play/p/PPBT4Fp-V3B
|
|
variantHelpers: []
|
|
similarHelpers:
|
|
- core#slice#countvalues
|
|
position: 203
|
|
---
|
|
|
|
CountValues counts the number of each element in the collection.
|
|
|
|
```go
|
|
collection := func(yield func(string) bool) {
|
|
yield("apple")
|
|
yield("banana")
|
|
yield("apple")
|
|
yield("cherry")
|
|
yield("banana")
|
|
yield("apple")
|
|
}
|
|
|
|
counts := it.CountValues(collection)
|
|
// counts contains {"apple": 3, "banana": 2, "cherry": 1}
|
|
``` |