Skip to main content

mapLeft

Callable

  • mapLeft<E, T>(x: E, f: (l: E extends Left<L> ? L : never) => T): E extends Left<unknown> ? Left<T> : E

  • If the given Either is a Right, return it, otherwise return a new Left with the result of applying the given function to the Left value.

    Example

    mapLeft({ left: 'bar' }, (x) => `${x}${x}`)
    // => { left: "barbar" }

    mapLeft({ right: 'bar' }, (x) => `${x}${x}`)
    // => { right: "bar" }

    Type parameters

    • E: Either<unknown, unknown>
    • T

      The mapped type.

    Parameters

    • x: E

      The either value to map.

    • f: (l: E extends Left<L> ? L : never) => T

      The map function.

    Returns E extends Left<unknown> ? Left<T> : E

    The mapped either object.