This commit is contained in:
Mike Schwörer 2023-02-16 13:22:15 +01:00
parent 4fd768e573
commit 22ce2d26f3
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF

View File

@ -273,6 +273,18 @@ func ArrMapExt[T1 any, T2 any](arr []T1, conv func(idx int, v T1) T2) []T2 {
return r return r
} }
func ArrMapErr[T1 any, T2 any](arr []T1, conv func(v T1) (T2, error)) ([]T2, error) {
var err error
r := make([]T2, len(arr))
for i, v := range arr {
r[i], err = conv(v)
if err != nil {
return nil, err
}
}
return r, nil
}
func ArrFilterMap[T1 any, T2 any](arr []T1, filter func(v T1) bool, conv func(v T1) T2) []T2 { 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)) r := make([]T2, 0, len(arr))
for _, v := range arr { for _, v := range arr {