Skip to content
Node: _.invert(obj)github.com/sahilkhaire/gox/maputil

Invert

Overview

Invert swaps keys and values; duplicate values overwrite (lodash invert).

If you are coming from Node.js, the closest pattern is _.invert(obj).

Signature

go
func Invert[K, V comparable](m map[K]V) map[V]K

Compare: Node.js · Standard Go · gox

js
_.invert(obj)
go
// Use the underlying stdlib or driver directly.
// See package overview for escape hatches.
go
import "github.com/sahilkhaire/gox/maputil"

maputil.Invert(obj)

Example

go
import "github.com/sahilkhaire/gox/maputil"

maputil.Invert(obj)

Tips

Import github.com/sahilkhaire/gox/maputil and call Invert directly. See the comparison below for the standard library equivalent.

Standard library alternative

gox wraps the Go standard library or a trusted dependency with Node-familiar naming. You can use the underlying library directly — see the package overview for escape hatches.

Back to maputil package overview

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