maputils

package
v0.0.0-...-b32fc0d Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Apache-2.0 Imports: 6 Imported by: 25

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterByKey

func FilterByKey[M ~map[K]V, K comparable, V any](m M, matcher matcher.Matcher[K]) M

func FilterByValue

func FilterByValue[M ~map[K]V, K comparable, V any](m M, matcher matcher.Matcher[V]) M

func FilterKeys

func FilterKeys[M ~map[K]V, K comparable, V any](m M, matcher matcher.Matcher[K]) []V

func FilterValues

func FilterValues[M ~map[K]V, K comparable, V any](m M, matcher matcher.Matcher[V]) []V

func FoldKV

func FoldKV[M ~map[K]E, K comparable, E any, F any](m M, init F, consume func(k K, e E, acc F) F) F

FoldKV provides an aggregation of all elements of a map using an incremental aggregation function, which combines a slice element and its key with an intermediate aggregation result starting with a given initial value.

func FoldSKV

func FoldSKV[M ~map[K]E, K cmp.Ordered, E any, F any](m M, init F, consume func(k K, e E, acc F) F) F

FoldSKV provides an aggregation of all elements of a map using an incremental aggregation function, which combines a slice element and its key with an intermediate aggregation result starting with a given initial value. The entry order is determined by the ordered key values.

func FoldSKVFunc

func FoldSKVFunc[M ~map[K]E, K cmp.Ordered, E any, F any](m M, init F, consume func(k K, e E, acc F) F, cmp CompareFunc[K]) F

FoldSKVFunc provides an aggregation of all elements of a map using an incremental aggregation function, which combines a slice element and its key with an intermediate aggregation result starting with a given initial value. The entry order is determined by the sort function on the key values.

func FoldSV

func FoldSV[M ~map[K]E, K cmp.Ordered, E any, F any](m M, init F, consume func(e E, acc F) F) F

FoldSV provides an aggregation of all elements of a map using an incremental aggregation function, which combines a map element with an intermediate aggregation result starting with a given initial value. The entry order is determined by the ordered values.

func FoldSVFunc

func FoldSVFunc[M ~map[K]E, K cmp.Ordered, E any, F any](m M, init F, consume func(e E, acc F) F, cmp CompareFunc[K]) F

FoldSVFunc provides an aggregation of all elements of a map using an incremental aggregation function, which combines a map element with an intermediate aggregation result starting with a given initial value. The entry order is determined by the sort function on the key values.

func FoldV

func FoldV[M ~map[K]E, K comparable, E any, F any](m M, init F, consume func(e E, acc F) F) F

FoldV provides an aggregation of all elements of a map using an incremental aggregation function, which combines a map element with an intermediate aggregation result starting with a given initial value.

func Keys

func Keys[M ~map[K]V, K comparable, V any](m M, cmp ...CompareFunc[K]) []K

Keys provides a list of keys optionally sorted by a CompareFunc.

func OrderedKeys

func OrderedKeys[M ~map[K]V, K cmp.Ordered, V any](m M) []K

OrderedKeys provides an ordered key list for maps with an ordered key type.

func OrderedTransformedKeys

func OrderedTransformedKeys[M ~map[K]V, K comparable, V any, TK cmp.Ordered](in M, m transformer.Transformer[K, TK]) []TK

func OrderedTransformedValues

func OrderedTransformedValues[M ~map[K]V, K comparable, V any, TV cmp.Ordered](in M, m transformer.Transformer[V, TV]) []TV

func OrderedValues

func OrderedValues[M ~map[K]V, K cmp.Ordered, V any](m M) []V

OrderedValues returns values optionally ordered by ordered keys.

func Transform

func Transform[M ~map[K]V, K comparable, V any, TK comparable, TV any](in M, m Transformer[K, V, TK, TV]) map[TK]TV

func TransformKeys

func TransformKeys[M ~map[K]V, K comparable, V any, TK comparable](in M, m transformer.Transformer[K, TK]) map[TK]V

func TransformValues

func TransformValues[M ~map[K]V, K comparable, V any, TV any](in M, m transformer.Transformer[V, TV]) map[K]TV

func TransformedKeys

func TransformedKeys[M ~map[K]V, K comparable, V any, TK comparable](in M, m transformer.Transformer[K, TK], cmp ...CompareFunc[TK]) []TK

func TransformedValues

func TransformedValues[M ~map[K]V, K comparable, V any, TV any](in M, m transformer.Transformer[V, TV], cmp ...CompareFunc[TV]) []TV

func Values

func Values[M ~map[K]V, K comparable, V any](m M, cmp ...CompareFunc[K]) []V

Values returns values optionally ordered by keys.

Types

type CompareFunc

type CompareFunc[E any] func(a, b E) int

type Transformer

type Transformer[K, V, TK, TV any] func(K, V) (TK, TV)

func KeyValueTransformer

func KeyValueTransformer[K, V, TK, TV any](tk transformer.Transformer[K, TK], tv transformer.Transformer[V, TV]) Transformer[K, V, TK, TV]

Jump to

Keyboard shortcuts

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