maps

package
v1.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 1 Imported by: 2

Documentation

Overview

Package maps contains utility functions for working with Go maps.

Index

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 FromPairs

func FromPairs[K comparable, V any](pairs iter.Of[iter.Pair[K, V]]) (map[K]V, error)

FromPairs produces a new map from an iterator of key-value pairs.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL