MCPcopy Create free account
hub / github.com/dolthub/doltgresql / SliceToMapValues

Function SliceToMapValues

utils/slice_to_map.go:28–34  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
28func 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}

Callers 1

assignTableDefFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected