Documentation ¶
Index ¶
- func Contains[K comparable, V any](map_ map[K]V, key K) bool
- func ContainsAll[K comparable, V any](map_ map[K]V, keys ...K) bool
- func ContainsAny[K comparable, V any](map_ map[K]V, keys ...K) bool
- func Duplicate[K comparable, V any](src map[K]V) map[K]V
- func Equal[K comparable, V comparable](m1, m2 map[K]V) bool
- func EqualFunc[K comparable, V any](m1, m2 map[K]V, test func(v1, v2 V) bool) bool
- func EqualT[K comparable, V types.Equaler[V]](m1, m2 map[K]V) bool
- func ExtractKeys[K comparable, V any](map_ map[K]V) []K
- func ExtractValues[K comparable, V any](map_ map[K]V) []V
- func Filter[K comparable, V any](input map[K]V, filter func(K, V) bool) map[K]V
- func Fold[K comparable, V any, F any](input map[K]V, initial F, fold func(F, K, V) F) F
- func FoldKeys[K comparable, V any, F any](input map[K]V, initial F, fold func(F, K) F) F
- func FoldValues[K comparable, V any, F any](input map[K]V, initial F, fold func(F, V) F) F
- func GetOr[K comparable, V any](map_ map[K]V, key K, defvalue V) V
- func KeySubset[K comparable, V any](set, subset map[K]V) bool
- func Merge[K comparable, V any](map1, map2 map[K]V) map[K]V
- func MergeInto[K comparable, V any](dst, src map[K]V)
- func MergeIntoFunc[K comparable, V any](dst, src map[K]V, resolve func(V, V) V)
- func MergeIntoKeyedFunc[K comparable, V any](dst, src map[K]V, resolve func(K, V, V) V)
- func Transform[KIN, KOUT comparable, VIN, VOUT any](input map[KIN]VIN, transform func(KIN, VIN) (KOUT, VOUT)) map[KOUT]VOUT
- func TransformKeys[KIN comparable, KOUT comparable, V any](input map[KIN]V, transform func(KIN, V) KOUT) map[KOUT]V
- func TransformValues[K comparable, VIN any, VOUT any](input map[K]VIN, transform func(K, VIN) VOUT) map[K]VOUT
- func UpdateValue[K comparable, V any](data map[K]V, update func(K, V) V)
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 Equal ¶
func Equal[K comparable, V comparable](m1, m2 map[K]V) bool
Equal checks equality of maps, with values required to be comparable. Every key is expected to be present in both maps and their corresponding values retrieved. Maps are considered not equal if one key is absent in the other map. FIXME needs testing
func EqualFunc ¶
func EqualFunc[K comparable, V any](m1, m2 map[K]V, test func(v1, v2 V) bool) bool
EqualFunc checks equality of maps, with each value in the map being tested using the provided `test` function/closure. `test` returns true iff values are considered equal, false otherwise. Every key is expected to be present in both maps and their corresponding values retrieved. Maps are considered not equal if one key is not present in the other map. FIXME needs testing
func EqualT ¶
func EqualT[K comparable, V types.Equaler[V]](m1, m2 map[K]V) bool
EqualT checks equality of maps, with each value in the map expected to implement builtin.Equaler. Every key is expected to be present in both maps and their corresponding values retrieved. Maps are considered not equal if one key is absent in the other map. FIXME needs testing
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, 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, resolve func(V, V) V)
MergeIntoFunc merges two maps, and calls `resolve` in case a key exists in both maps. `resolve` takes only values (see `MergeFunc` for conflict func that includes parameter for `K`) and uses the value returned by `resolve`.
func MergeIntoKeyedFunc ¶
func MergeIntoKeyedFunc[K comparable, V any](dst, src map[K]V, resolve 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 `resolve` 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.