• Returns fn() if resA is an Err, otherwise returns the success resA. The order of arguments is reversed because of that it is useful for partial applying.

    Type Parameters

    • F

    • T

    • E

    Parameters

    • fn: ((error) => Result<E, T>)

      The second result.

    Returns ((resA) => Result<E, T>)

    resA or fn().

    Examples

    import { err, ok, orElse } from "./result.ts";
    import { assertEquals } from "../deps.ts";

    const sq = orElse((x: number) => ok<number>(x * x));
    const residual = orElse((x: number) => err<number>(x));

    assertEquals(sq(sq(ok(2))), ok(2));
    assertEquals(sq(residual(ok(2))), ok(2));
    assertEquals(residual(sq(err(3))), ok(9));
    assertEquals(residual(residual(err(3))), err(3));

Generated using TypeDoc