xmap

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 3 Imported by: 0

README

xmap

import "github.com/dashjay/xiter/pkg/xmap"

Index

func Clone

func Clone[M ~map[K]V, K comparable, V any](m M) M

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

Generated by gomarkdoc

Documentation

Index

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.

Jump to

Keyboard shortcuts

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