Documentation
¶
Overview ¶
Package maps provides some functions for working with Go maps.
Index ¶
- func Clear[K comparable, V any](m map[K]V)
- func Clone[K comparable, V any](m map[K]V) map[K]V
- func Contains[K comparable, V any](m map[K]V, key K) bool
- func Equal[K, V comparable](m1, m2 map[K]V) bool
- func EqualFunc[K comparable, V any](m1, m2 map[K]V, equal func(v1, v2 V) bool) bool
- func FromItems[K comparable, V any](items []Item[K, V]) map[K]V
- func FromSlices[K comparable, V any](keys []K, values []V) map[K]V
- func Get[K comparable, V any](m map[K]V, key K, dflt V) V
- func Keys[K comparable, V any](m map[K]V) []K
- func KeysForValue[K, V comparable](m map[K]V, value V) []K
- func KeysForValueFunc[K, V comparable](m map[K]V, value V, equal func(v1, v2 V) bool) []K
- func Update[K comparable, V any](m1, m2 map[K]V)
- func Values[K comparable, V any](m map[K]V) []V
- type Item
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[K comparable, V any](m map[K]V, key K) bool
Contains returns true if key is in map m.
func Equal ¶
func Equal[K, V comparable](m1, m2 map[K]V) bool
Equal returns true if the two maps are equal (containing the same keys with the same values).
func EqualFunc ¶
func EqualFunc[K comparable, V any](m1, m2 map[K]V, equal func(v1, v2 V) bool) bool
EqualFunc returns true if the two maps are equal using a function to compare values.
func FromItems ¶
func FromItems[K comparable, V any](items []Item[K, V]) map[K]V
FromItems makes a map from a slice of Item objects.
func FromSlices ¶
func FromSlices[K comparable, V any](keys []K, values []V) map[K]V
FromSlices makes a map from two slices. If the keys slice is longer then the values slice, the surplus keys will have the null value of type T as their value. Surplus values will be ignored.
func Get ¶
func Get[K comparable, V any](m map[K]V, key K, dflt V) V
Get returns the value for key from map m or a default value.
func Keys ¶
func Keys[K comparable, V any](m map[K]V) []K
Keys returns a slice with all keys from map m.
func KeysForValue ¶
func KeysForValue[K, V comparable](m map[K]V, value V) []K
KeysForValue returns a slice with keys which have the given value.
func KeysForValueFunc ¶
func KeysForValueFunc[K, V comparable](m map[K]V, value V, equal func(v1, v2 V) bool) []K
KeysForValueFunc returns a slice with keys which have the given value using a function to compare values.
func Update ¶
func Update[K comparable, V any](m1, m2 map[K]V)
Update updates a map with items from another map.
func Values ¶
func Values[K comparable, V any](m map[K]V) []V
Values returns a slice with all values from map m.
Types ¶
type Item ¶
type Item[K comparable, V any] struct { Key K Value V }
Type Item represents a key-value pair.