Documentation
¶
Index ¶
- func Clone[M ~map[K]V, K comparable, V any](m M) M
- func CoalesceMaps[M ~map[K]V, K comparable, V any](maps ...M) M
- func Copy[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2)
- func Equal[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool
- func EqualFunc[M1 ~map[K]V1, M2 ~map[K]V2, K comparable, V1, V2 any](m1 M1, m2 M2, eq func(V1, V2) bool) bool
- func Keys[M ~map[K]V, K comparable, V any](m M) []K
- func ToUnionSlice[M ~map[K]V, K comparable, V any](m M) []union.U2[K, V]
- func Values[M ~map[K]V, K comparable, V any](m M) []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clone ¶
func Clone[M ~map[K]V, K comparable, V any](m M) M
func CoalesceMaps ¶
func CoalesceMaps[M ~map[K]V, K comparable, V any](maps ...M) M
CoalesceMaps combines multiple maps into a single map. When duplicate keys are encountered, the value from the rightmost (last) map in the input slice takes precedence. It iterates through the input maps, converts them to sequences of key-value pairs, concatenates these sequences, and then converts the combined sequence back into a new map.
Parameters:
maps ...M: A variadic slice of maps of type M. Each map must have comparable keys K and values V.
Returns:
M: A new map containing all key-value pairs from the input maps, with later maps overriding values for duplicate keys.
Example:
map1 := map[string]int{"a": 1, "b": 2}
map2 := map[string]int{"b": 3, "c": 4}
map3 := map[string]int{"d": 5}
// CoalesceMaps will combine map1, map2, and map3.
// For key "b", the value 3 from map2 will override 2 from map1.
result := CoalesceMaps(map1, map2, map3)
// result will be map[string]int{"a": 1, "b": 3, "c": 4, "d": 5}
func Copy ¶
func Copy[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2)
func Equal ¶
func Equal[M1, M2 ~map[K]V, K, V comparable](m1 M1, m2 M2) bool
func EqualFunc ¶
func EqualFunc[M1 ~map[K]V1, M2 ~map[K]V2, K comparable, V1, V2 any](m1 M1, m2 M2, eq func(V1, V2) bool) bool
func Keys ¶
func Keys[M ~map[K]V, K comparable, V any](m M) []K
func ToUnionSlice ¶
func ToUnionSlice[M ~map[K]V, K comparable, V any](m M) []union.U2[K, V]
func Values ¶
func Values[M ~map[K]V, K comparable, V any](m M) []V
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.