mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
Updating count to work with any so you can count structs as well as basic types
This commit is contained in:
parent
b1cb7899bb
commit
8b0b7f5c67
1 changed files with 1 additions and 1 deletions
2
count.go
2
count.go
|
|
@ -2,7 +2,7 @@ package underscore
|
|||
|
||||
// Count returns the number of elements in the slice that satisfy the predicate.
|
||||
// example: Count([]int{1,2,3,4,5}, func(n int) bool { return n%2 == 0 }) // 2
|
||||
func Count[T comparable](slice []T, predicate func(T) bool) int {
|
||||
func Count[T any](slice []T, predicate func(T) bool) int {
|
||||
count := 0
|
||||
for _, item := range slice {
|
||||
if predicate(item) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue