Skip to main content

mapLefts

Callable

  • mapLefts<Xs, T>(xs: readonly [Xs], f: (ls: ArgLefts<Xs>) => T): ArgLefts<Xs> extends never[] ? Right<ArgRights<Xs>[number]> : ArgRights<Xs>[number] extends never[] ? Left<T> : Left<T> | Right<ArgRights<Xs>[number]>

  • mapLefts takes a tuple of Eithers and a function that takes the left values of the Eithers and returns a new Either with the left value being the result of the function and the right value being the right value of the first Either in the tuple.

    Example

    mapLefts([{ left: 'foo' }, { left: 'bar' }], ([x0, x1]) => `${x0}${x1}`)
    // => { left: "foobar" }

    mapLefts([{ right: 'bar' }, { left: 'fooz' }], ([x0, x1]) => `${x0}${x1}`)
    // => { right: "bar" }

    Type parameters

    • Xs: Either<unknown, unknown>[]
    • T

      The mapped type.

    Parameters

    • xs: readonly [Xs]

      The either values to map.

    • f: (ls: ArgLefts<Xs>) => T

      The map function.

    Returns ArgLefts<Xs> extends never[] ? Right<ArgRights<Xs>[number]> : ArgRights<Xs>[number] extends never[] ? Left<T> : Left<T> | Right<ArgRights<Xs>[number]>

    The mapped either object.