v0.0.95
This commit is contained in:
parent
007c44df85
commit
289b9f47a2
@ -265,6 +265,26 @@ func ArrMap[T1 any, T2 any](arr []T1, conv func(v T1) T2) []T2 {
|
||||
return r
|
||||
}
|
||||
|
||||
func MapMap[TK comparable, TV any, TR any](inmap map[TK]TV, conv func(k TK, v TV) TR) []TR {
|
||||
r := make([]TR, 0, len(inmap))
|
||||
for k, v := range inmap {
|
||||
r = append(r, conv(k, v))
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func MapMapErr[TK comparable, TV any, TR any](inmap map[TK]TV, conv func(k TK, v TV) (TR, error)) ([]TR, error) {
|
||||
r := make([]TR, 0, len(inmap))
|
||||
for k, v := range inmap {
|
||||
elem, err := conv(k, v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r = append(r, elem)
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func ArrMapExt[T1 any, T2 any](arr []T1, conv func(idx int, v T1) T2) []T2 {
|
||||
r := make([]T2, len(arr))
|
||||
for i, v := range arr {
|
||||
|
Loading…
Reference in New Issue
Block a user