diff --git a/langext/array.go b/langext/array.go index 7f53a06..a4b875f 100644 --- a/langext/array.go +++ b/langext/array.go @@ -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 {