• Transforms the optional value into Result with the error e().

    Type Parameters

    • E

    Parameters

    • e: (() => E)

      The function provides an error used when opt is a None.

        • (): E
        • Returns E

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

    The new Result.

    Examples

    import { okOrElse, some, none } from "./option.ts";
    import { err, ok } from "./result.ts";
    import { assertEquals } from "../deps.ts";

    const orZero = okOrElse(() => 0);

    assertEquals(orZero(some("foo")), ok("foo"));
    assertEquals(orZero(none()), err(0));

Generated using TypeDoc