Files
lo/docs/data/core-countvaluesby.md
T
2025-10-06 17:15:49 +02:00

649 B

name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
name slug sourceRef category subCategory playUrl variantHelpers similarHelpers position signatures
CountValuesBy countvaluesby slice.go#L623 core slice https://go.dev/play/p/2U0dG1SnOmS
core#slice#countvaluesby
core#slice#countvalues
core#slice#groupby
core#slice#map
core#slice#mapvalues
0
func CountValuesBy[T any, U comparable](collection []T, mapper func(item T) U) map[U]int

Counts the number of each mapped value (equivalent to Map followed by CountValues).

isEven := func(v int) bool {
    return v%2 == 0
}
lo.CountValuesBy([]int{1, 2, 2}, isEven)
// map[bool]int{false: 1, true: 2}