maps

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect added in v0.1.10

func Collect[K comparable, V any, W any](m map[K]V, f func(V) W) map[K]W

Collect map through given function. If the input is nil, it will return nil; if the input is empty, it will return an empty map. Otherweise, it will return return a map of the same length as the input map, containing the same keys, and the values mapped through the provided function f.

func Equal

func Equal[K comparable, V comparable](m map[K]V, n map[K]V) bool

Compare two maps of comparable values. Maps with different length are never equal. Empty and nil maps are always equal (in particular, comparing an empty with a nil map yields true). Otherwise, the two maps are equal if corresponding values are equal by means of the == operator.

func EqualBy

func EqualBy[K comparable, V any, W any](m map[K]V, n map[K]W, f func(V, W) bool) bool

Compare two maps by a given equality function (for values, keys are still compared by ==). Maps with different length are never equal. Empty and nil maps are always equal (in particular, comparing an empty with a nil map yields true). Otherwise, the two maps are equal if corresponding values are equal by means of the provided equality function.

func Keys

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

Get keys of map. If the input is nil, it will return a nil slice; otherwise, if the input is empty, it will return an empty slice. Otherwise it will return a slice containing the keys of the given map. Note that there is not guarantee about the order of the returned keys.

func Select added in v0.2.4

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

Select sub-map from map by given function. If the input is nil, it will return nil; if the input is empty, it will return an empty map. Otherwise, it will return a map containing the keys and according values, for which the provided function f evaluates to true.

func SelectByKeys added in v0.2.4

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

Select sub-map from map by the given keys. If the input is nil, it will return nil; if the input is empty, it will return an empty map. Otherwise, it will return a map containing those keys and according values, if existing in the input map; Keys which do not exist in the input map will be ignored.

func Values

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

Get values of map. If the input is nil, it will return a nil slice; otherwise, if the input is empty, it will return an empty slice. Otherwise it will return a slice containing the values of the given map (repeating identical values, if any). Note that there is not guarantee about the order of the returned values.

Types

This section is empty.

Jump to

Keyboard shortcuts

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