Skip to content

Commit

Permalink
add Count feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ixiongjianbo committed Jul 4, 2023
1 parent 860ef23 commit 1db70c9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,18 @@ func Index[T any](list []T, index int) T {
}
return list[index]
}

// Count example:
//
// count := Count(ss, func(i int, row *T2) bool {
// return row.Name == `A1`
// })
func Count[T any](array []T, fc func(i int, row T) bool) int {
count := 0
for i, row := range array {
if fc(i, row) {
count++
}
}
return count
}

0 comments on commit 1db70c9

Please sign in to comment.