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
890 B
890 B
name, slug, sourceRef, category, subCategory, signatures, variantHelpers, playUrl, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | variantHelpers | playUrl | similarHelpers | position | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| CountByErr | countbyerr | slice.go#L863 | core | slice |
|
|
https://go.dev/play/p/7BnyPhpG6lW |
|
5 |
Counts the number of elements for which the predicate is true. Returns an error if the predicate function fails, stopping iteration immediately.
count, err := lo.CountByErr([]int{1, 5, 1}, func(i int) (bool, error) {
if i == 5 {
return false, fmt.Errorf("5 not allowed")
}
return i < 4, nil
})
// 0, error("5 not allowed")
count, err := lo.CountByErr([]int{1, 5, 1}, func(i int) (bool, error) {
return i < 4, nil
})
// 2, nil