maputil

package
v0.0.0-...-9727c61 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyKey

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

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

func AnyVal

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

AnyVal returns an arbitrary value of the map m. If m is not empty, the second return value is true. If the map is empty, AnyVal 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 FromSlices

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 GetValues

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

GetValues returns a slice containing all values of map m in arbitrary order.

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 IterateSortedCustom

func IterateSortedCustom[K comparable, V any](m map[K]V, f func(K, V) bool, less func(K, K) bool)

func RemoveAll

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

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