Back to Lo

Core Unzipbyerrx

docs/data/core-unzipbyerrx.md

1.53.0588 B
Original Source

Transforms each input element into a tuple and splits results into parallel slices. The iteratee can return an error to stop iteration immediately. Variants support arities from 2 to 9.

Variants: UnzipByErr2..UnzipByErr9

go
a, b, err := lo.UnzipByErr2([]string{"hello", "error", "world"}, func(str string) (string, int, error) {
    if str == "error" {
        return "", 0, fmt.Errorf("error string not allowed")
    }
    return str, len(str), nil
})
// []string{}
// []int{}
// error string not allowed

On error, all result slices are nil and iteration stops immediately.