mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 10:36:43 +00:00
16 lines
369 B
Go
16 lines
369 B
Go
package maps
|
|
|
|
type M[K comparable, V any] map[K]V
|
|
|
|
// Map produces a new slice of values by mapping each value in the slice through
|
|
// a transform function.
|
|
func Map[K, Q comparable, V, W any](m M[K, V], f func(K, V) M[Q, W]) M[Q, W] {
|
|
res := make(M[Q, W], len(m))
|
|
for k, v := range m {
|
|
mm := f(k, v)
|
|
for k2, v2 := range mm {
|
|
res[k2] = v2
|
|
}
|
|
}
|
|
return res
|
|
}
|