Documentation ¶
Overview ¶
Package maps contains utility functions for working with Go maps.
Index ¶
- func Dup[K comparable, V any](m map[K]V) map[K]V
- func Each[K comparable, V any](m map[K]V, f func(K, V) error) error
- func Equal[K, V comparable](a, b map[K]V) bool
- func FromPairs[K comparable, V any](pairs iter.Of[iter.Pair[K, V]]) (map[K]V, error)
- func Invert[K, V comparable](m map[K]V) map[V]K
- func InvertMulti[K, V comparable](m map[K]V) map[V][]K
- func Keys[K comparable, V any](m map[K]V) []K
- func Values[K comparable, V any](m map[K]V) []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dup ¶
func Dup[K comparable, V any](m map[K]V) map[K]V
Dup makes a (shallow) duplicate of the given map.
func Each ¶
func Each[K comparable, V any](m map[K]V, f func(K, V) error) error
Each calls a function on each key-value pair in the given map. If the function returns an error, Each exits early with that error.
func Equal ¶
func Equal[K, V comparable](a, b map[K]V) bool
Equal tests whether two maps are equal to each other. The values in the maps must be "comparable."
func Invert ¶
func Invert[K, V comparable](m map[K]V) map[V]K
Invert inverts the key-value pairs in the given map, producing a new map with the values as keys and the keys as values. If any of the values in the input are duplicates, an indeterminate one will survive with its key while the others will be silently dropped.
func InvertMulti ¶ added in v1.3.0
func InvertMulti[K, V comparable](m map[K]V) map[V][]K
InvertMulti inverts the key-value pairs in the map. It is like Invert but handles duplicate values: the key slice contains all the keys that map to the same value.
func Keys ¶ added in v1.1.0
func Keys[K comparable, V any](m map[K]V) []K
Keys returns a slice of the keys in m.
func Values ¶ added in v1.2.0
func Values[K comparable, V any](m map[K]V) []V
Values returns a slice of the values in m.
Types ¶
This section is empty.