name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
name
slug
sourceRef
category
subCategory
signatures
variantHelpers
similarHelpers
position
MapErr
maperr
slice.go#L36
core
slice
func MapErr[T any, R any](collection []T, transform func(item T, index int) (R, error)) ([]R, error)
core#slice#maperr
core#slice#map
core#slice#filtermap
core#slice#flatmap
core#slice#rejectmap
parallel#slice#map
11
Transforms each element in a slice to a new type using a function that can return an error. Stops iteration immediately when an error is encountered.
// Error case - stops on first errorresult,err:=lo.MapErr([]int{1,2,3,4},func(xint,_int)(string,error){ifx==3{return"",fmt.Errorf("number 3 is not allowed")}returnstrconv.Itoa(x),nil})// []string(nil), error("number 3 is not allowed")