Omit
Overview
Omit returns a new map without the given keys (lodash omit).
If you are coming from Node.js, the closest pattern is _.omit(obj, keys).
Signature
go
func Omit[K comparable, V any](m map[K]V, keys ...K) map[K]VCompare: Node.js · Standard Go · gox
js
_.omit(obj, keys)go
out := make(map[string]any)
for k, v := range obj { /* copy keys */ }go
import "github.com/sahilkhaire/gox/maputil"
maputil.Omit(obj, keys...)Example
go
import "github.com/sahilkhaire/gox/maputil"
maputil.Omit(obj, keys...)Tips
Import github.com/sahilkhaire/gox/maputil and call Omit directly. See the comparison below for the standard library equivalent.
Standard library alternative
Use the standard library directly:
go
out := make(map[string]any)
for k, v := range obj { /* copy keys */ }