Files
lo/docs/data/core-countby.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

32 lines
570 B
Markdown

---
name: CountBy
slug: countby
sourceRef: slice.go#L849
category: core
subCategory: slice
playUrl: https://go.dev/play/p/5GMQP5vNT4q
variantHelpers:
- core#slice#countby
similarHelpers:
- core#slice#count
- core#slice#every
- core#slice#some
- core#slice#filter
- core#slice#find
- core#slice#countbyerr
position: 0
signatures:
- "func CountBy[T any](collection []T, predicate func(item T) bool) int"
---
Counts the number of elements for which the predicate is true.
```go
lo.CountBy([]int{1, 5, 1}, func(i int) bool {
return i < 4
})
// 2
```