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