docs/data/core-zipbyerrx.md
Zips multiple slices and projects each grouped set through a function that can return an error. Stops iteration immediately when an error is encountered and returns the zero value (nil for slices).
Variants: ZipByErr2..ZipByErr9
result, err := lo.ZipByErr2([]string{"a", "b"}, []int{1, 2}, func(a string, b int) (string, error) {
if b == 2 {
return "", fmt.Errorf("number 2 is not allowed")
}
return fmt.Sprintf("%s-%d", a, b), nil
})
// []string(nil), error("number 2 is not allowed")
result, err := lo.ZipByErr2([]string{"a", "b"}, []int{1, 2}, func(a string, b int) (string, error) {
return fmt.Sprintf("%s-%d", a, b), nil
})
// []string{"a-1", "b-2"}, nil
When collections are different sizes, the missing attributes are filled with zero value before calling the iteratee.