maputil

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any[K comparable, V any](m map[K]V) (V, bool)

Any returns an arbitrary element of the map m. If m is not empty, the second return value is true. If the map is empty, Any returns the zero value of the m's value type and false.

func Copy

func Copy[K comparable, V any](m map[K]V) map[K]V

func FindAndDeleteAll added in v0.3.0

func FindAndDeleteAll[K comparable, V any](m map[K]V, f func(key K, value V) bool)

func FromSlices added in v0.2.0

func FromSlices[K comparable, V any](keys []K, vals []V) map[K]V

FromSlices constructs and returns a map from two separate slices of keys and corresponding values. FromSlices panics if the number of keys differs from the number of values.

func GetKeys

func GetKeys[K comparable, V any](m map[K]V) []K

GetKeys returns a slice containing all keys of map m in arbitrary order.

func GetKeysAndValues

func GetKeysAndValues[K comparable, V any](m map[K]V) ([]K, []V)

GetKeysAndValues returns a slice containing all keys of map m (in arbitrary order) and a slice containing the corresponding values, in the corresponding order.

statement

keys, values := GetKeysAndValues(m)

is equivalent to:

keys := GetKeys(m)
values := GetValuesOf(m, keys)

func GetSortedKeys

func GetSortedKeys[K constraints.Ordered, V any](m map[K]V) []K

func GetValuesOf

func GetValuesOf[K comparable, V any](m map[K]V, keys []K) []V

GetValuesOf returns a slice containing the values from map m corresponding to the provided keys, in the same order as the keys.

func IterateSorted

func IterateSorted[K constraints.Ordered, V any](m map[K]V, f func(key K, value V) (cont bool))

func Transform

func Transform[Ki comparable, Vi any, Ko comparable, Vo any](mi map[Ki]Vi, f func(Ki, Vi) (Ko, Vo)) map[Ko]Vo

Types

This section is empty.

Jump to

Keyboard shortcuts

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