name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
name
slug
sourceRef
category
subCategory
signatures
variantHelpers
similarHelpers
position
MapKeysErr
mapkeyserr
map.go#L293
core
map
func MapKeysErr[K comparable, V any, R comparable](in map[K]V, iteratee func(value V, key K) (R, error)) (map[R]V, error)
core#map#mapkeyserr
core#map#mapkeys
core#map#mapvalueserr
185
Transforms map keys using a predicate while keeping values. Returns an error if the iteratee function fails, stopping iteration immediately.
in:=map[int]int{1:1,2:2,3:3}out,err:=lo.MapKeysErr(in,func(vint,_int)(string,error){ifv==2{return"",fmt.Errorf("even number not allowed")}returnstrconv.Itoa(v),nil})// map[string]int(nil), error("even number not allowed")