2
0

maputil.go 322 B

1234567891011
  1. package maputil
  2. // Map applies a transformation function to each value within a map to get a new map containing the
  3. // transformed values.
  4. func Map[K comparable, V any, T any](m map[K]V, transform func(V) T) map[K]T {
  5. result := make(map[K]T, len(m))
  6. for k, v := range m {
  7. result[k] = transform(v)
  8. }
  9. return result
  10. }