mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.2 KiB
1.2 KiB
name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | variantHelpers | similarHelpers | position | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Assign | assign | it/map.go#L122 | it | map |
|
|
|
50 |
Merges multiple map sequences into a single map. Later maps overwrite values from earlier maps when keys conflict.
map1 := func(yield func(map[string]int) bool) {
yield(map[string]int{"a": 1, "b": 2})
}
map2 := func(yield func(map[string]int) bool) {
yield(map[string]int{"b": 3, "c": 4})
}
map3 := func(yield func(map[string]int) bool) {
yield(map[string]int{"d": 5, "e": 6})
}
result := it.Assign(map1, map2, map3)
// map[string]int{"a": 1, "b": 3, "c": 4, "d": 5, "e": 6}
// Note: "b" is 3 (overwritten from map2)
singleMap := func(yield func(map[int]string) bool) {
yield(map[int]string{1: "one", 2: "two"})
}
result = it.Assign(singleMap)
// map[int]string{1: "one", 2: "two"}
emptyMap1 := func(yield func(map[string]bool) bool) {
yield(map[string]bool{})
}
emptyMap2 := func(yield func(map[string]bool) bool) {
yield(map[string]bool{"active": true})
}
result = it.Assign(emptyMap1, emptyMap2)
// map[string]bool{"active": true}