Merge
Overview
Merge copies keys from sources into dst, later maps override (lodash merge, shallow).
If you are coming from Node.js, the closest pattern is _.merge(a, b).
Signature
go
func Merge[K comparable, V any](dst map[K]V, sources ...map[K]V) map[K]VCompare: Node.js · Standard Go · gox
js
_.merge(a, b)go
out := maps.Clone(base)
maps.Copy(out, overlay)go
import "github.com/sahilkhaire/gox/maputil"
maputil.Merge(a, b)Example
go
import "github.com/sahilkhaire/gox/maputil"
maputil.Merge(a, b)Tips
Import github.com/sahilkhaire/gox/maputil and call Merge directly. See the comparison below for the standard library equivalent.
Standard library alternative
Use the standard library directly:
go
out := maps.Clone(base)
maps.Copy(out, overlay)