Documentation
¶
Overview ¶
Package mapx provides generic helpers for creating, cloning, merging, and querying maps and set-maps.
Index ¶
- func AppendOnce[K comparable, V any](key K, value V, m map[K][]V, seen map[K]struct{})
- func CloneMapStringSlice(src map[string][]string) map[string][]string
- func DeepCloneMapAny(src map[string]any) map[string]any
- func DeepMergeMapAny(base, override map[string]any) map[string]any
- func GetOrInit[K comparable, V any](m map[K]*V, key K, init func() *V) *V
- func MapIntersectionUnique[T comparable](left, right []T) []T
- func MapSetFromSlice[T comparable](items []T) map[T]struct{}
- func PruneMapZeroAny(src map[string]any) map[string]any
- func SortedProjection[K comparable, V any, T any, S cmp.Ordered](m map[K]V, project func(V) T, sortKey func(T) S) []T
- func SortedValues[K comparable, V any, S cmp.Ordered](m map[K]V, sortKey func(V) S) []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendOnce ¶ added in v1.23.15
func AppendOnce[K comparable, V any](key K, value V, m map[K][]V, seen map[K]struct{})
AppendOnce appends value to m[key] only if key has not been seen yet, preventing duplicate entries for the same key across multiple sources
func CloneMapStringSlice ¶
CloneMapStringSlice clones a map[string][]string, skipping blank keys
func DeepCloneMapAny ¶
DeepCloneMapAny creates a deep copy of a map[string]any
func DeepMergeMapAny ¶
DeepMergeMapAny deep-merges override onto base, recursing into nested map[string]any values
func GetOrInit ¶ added in v1.23.15
func GetOrInit[K comparable, V any](m map[K]*V, key K, init func() *V) *V
GetOrInit returns m[key] if it is non-nil, otherwise calls init, stores the result under key, and returns it
func MapIntersectionUnique ¶
func MapIntersectionUnique[T comparable](left, right []T) []T
MapIntersectionUnique returns items present in both slices, in right-hand order, with duplicates removed
func MapSetFromSlice ¶
func MapSetFromSlice[T comparable](items []T) map[T]struct{}
MapSetFromSlice converts a slice into a set represented as map[T]struct{}
func PruneMapZeroAny ¶
PruneMapZeroAny removes zero-value leaves from a nested map[string]any
func SortedProjection ¶ added in v1.15.0
func SortedProjection[K comparable, V any, T any, S cmp.Ordered](m map[K]V, project func(V) T, sortKey func(T) S) []T
SortedProjection projects map values into a target type and returns them sorted by sortKey
func SortedValues ¶ added in v1.15.0
func SortedValues[K comparable, V any, S cmp.Ordered](m map[K]V, sortKey func(V) S) []V
SortedValues returns map values sorted by a key derived from each value
Types ¶
This section is empty.