diff --git a/langext/maps.go b/langext/maps.go index a0e5b25..6f06ed4 100644 --- a/langext/maps.go +++ b/langext/maps.go @@ -7,3 +7,11 @@ func MapKeyArr[T comparable, V any](v map[T]V) []T { } return result } + +func ArrToMap[T comparable, V any](a []V, keyfunc func(V) T) map[T]V { + result := make(map[T]V, len(a)) + for _, v := range a { + result[keyfunc(v)] = v + } + return result +}