Skip to content
Node: _.merge(a, b)github.com/sahilkhaire/gox/maputil

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]V

Compare: 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)

← Back to maputil package overview

MIT Licensed · Built for Node.js developers moving to Go