v0.0.614 ArrCount
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m26s

This commit is contained in:
2025-11-29 12:49:17 +01:00
parent 69f2dd73c5
commit 34023dca4c
4 changed files with 57 additions and 16 deletions

View File

@@ -385,6 +385,7 @@ func ArrMapErr[T1 any, T2 any](arr []T1, conv func(v T1) (T2, error)) ([]T2, err
return r, nil
}
// ArrFilterMap returns a new array containing only the elements matching the filter, converted via conv (combines ArrFilter and ArrMap)
func ArrFilterMap[T1 any, T2 any](arr []T1, filter func(v T1) bool, conv func(v T1) T2) []T2 {
r := make([]T2, 0, len(arr))
for _, v := range arr {
@@ -395,6 +396,7 @@ func ArrFilterMap[T1 any, T2 any](arr []T1, filter func(v T1) bool, conv func(v
return r
}
// ArrFilter returns a new array containing only the elements matching the filter
func ArrFilter[T any](arr []T, filter func(v T) bool) []T {
r := make([]T, 0, len(arr))
for _, v := range arr {
@@ -405,6 +407,17 @@ func ArrFilter[T any](arr []T, filter func(v T) bool) []T {
return r
}
// ArrCount returns the number of elements matching the filter
func ArrCount[T any](arr []T, filter func(v T) bool) int {
c := 0
for _, v := range arr {
if filter(v) {
c++
}
}
return c
}
func ArrSum[T NumberConstraint](arr []T) T {
var r T = 0
for _, v := range arr {