SliceToMapValues converts the given slice into a map where all of the slice's values are keyed by the output of the `getKey` function, which takes a value and returns a key. It is up to the caller to return a unique key.
(slice []V, getKey func(V) K)
| 26 | // SliceToMapValues converts the given slice into a map where all of the slice's values are keyed by the output of the |
| 27 | // `getKey` function, which takes a value and returns a key. It is up to the caller to return a unique key. |
| 28 | func SliceToMapValues[K comparable, V any](slice []V, getKey func(V) K) map[K]V { |
| 29 | m := make(map[K]V) |
| 30 | for _, val := range slice { |
| 31 | m[getKey(val)] = val |
| 32 | } |
| 33 | return m |
| 34 | } |