maps

package
v0.0.0-...-34bb4ad Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: GPL-3.0, LGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[K comparable, V any](map_ map[K]V, key K) bool

Contains checks a map for the specified key.

func ContainsAll

func ContainsAll[K comparable, V any](map_ map[K]V, keys ...K) bool

ContainsAll checks whether all specified keys are present in the map. Returns `true` if all exist, or `false` otherwise.

func ContainsAny

func ContainsAny[K comparable, V any](map_ map[K]V, keys ...K) bool

ContainsAny checks whether any of the specified keys is present in the map. Returns `true` if any one occurrence is found, and returns on the first find. If no key is found, `false` is returned.

func Duplicate

func Duplicate[K comparable, V any](src map[K]V) map[K]V

Duplicate duplicates the map only. A shallow copy of map entries into a new map of equal size.

func ExtractKeys

func ExtractKeys[K comparable, V any](map_ map[K]V) []K

ExtractKeys extracts the keys from a map.

func ExtractValues

func ExtractValues[K comparable, V any](map_ map[K]V) []V

ExtractValues extracts the values from a map.

func Filter

func Filter[K comparable, V any](input map[K]V, filter func(K, V) bool) map[K]V

Filter filters a map according to the provided filter, returning a new map containing the filtered result.

func Fold

func Fold[K comparable, V any, F any](input map[K]V, initial F, fold func(F, K, V) F) F

Fold folds a map into a single representation of type R, based on both its keys and values.

func FoldKeys

func FoldKeys[K comparable, V any, F any](input map[K]V, initial F, fold func(F, K) F) F

FoldKeys uses provided folding function to fold keys into a single resulting value.

func FoldValues

func FoldValues[K comparable, V any, F any](input map[K]V, initial F, fold func(F, V) F) F

FoldValues uses provided folding function to fold values into a single resulting value.

func GetOr

func GetOr[K comparable, V any](map_ map[K]V, key K, defvalue V) V

GetOr gets the value for `key` from a map, or returns `defvalue` if key is not present.

func KeySubset

func KeySubset[K comparable, V any](set map[K]V, subset map[K]V) bool

KeySubset checks, `O(n)` for `n` entries, if all keys of `subset` map are present in `set` map. Values are not considered.

func Merge

func Merge[K comparable, V any](map1, map2 map[K]V) map[K]V

Merge merges `map1` and `map2` into a new merged map with same key and value type.

func MergeInto

func MergeInto[K comparable, V any](dst, src map[K]V)

MergeInto merges `src` map into `dst`. It requires all keys to be distinct. MergeMap will panic if a key is present in both maps. MergeMapFunc can be used if such conflict resolution is needed.

func MergeIntoFunc

func MergeIntoFunc[K comparable, V any](dst, src map[K]V, conflict func(V, V) V)

MergeIntoFunc merges two maps, and calls `conflict` in case a key exists in both maps. `conflict` takes only values (see `MergeFunc` for conflict func that includes parameter for `K`) and uses the value returned by `conflict`.

func MergeIntoKeyedFunc

func MergeIntoKeyedFunc[K comparable, V any](dst, src map[K]V, conflict func(K, V, V) V)

MergeIntoKeyedFunc merges two distinct maps into one destination map, freshly created. In case a key exists in both maps, func `conflict` is called for conflict resolution. It will return the desired value, which can be determined based on provided key and the original values from both maps.

func Transform

func Transform[KIN, KOUT comparable, VIN, VOUT any](input map[KIN]VIN,
	transform func(KIN, VIN) (KOUT, VOUT)) map[KOUT]VOUT

Transform transforms both keys and values of a map into the output types for keys and values. Transform assumes correct operation of the transformation function `f`. It will allow overlapping keys in the output map, possibly resulting in loss of values.

func TransformKeys

func TransformKeys[KIN comparable, KOUT comparable, V any](input map[KIN]V,
	transform func(KIN, V) KOUT) map[KOUT]V

TransformKeys transforms an input map into an output map, using different types for keys. Given that only keys are transformed, this implementation will assume that destination key types will not overlap. If the transformation maps to the same key more than once, execution will panic. This prevents losing values by overlapping destination keys.

func TransformValues

func TransformValues[K comparable, VIN any, VOUT any](input map[K]VIN,
	transform func(K, VIN) VOUT) map[K]VOUT

TransformValues transforms an input map into an output map, using different types for values.

func UpdateValue

func UpdateValue[K comparable, V any](data map[K]V, update func(K, V) V)

UpdateValue iterates over all values in a map and calls `update` to acquire an updated value for each entry in the map. UpdateValue updates the provided map.

Types

This section is empty.

Jump to

Keyboard shortcuts

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