• Returns the optional optA if it contains a value, otherwise calls optB and returns the result. The order of arguments is reversed because of that it is useful for partial applying.

    Type Parameters

    • T

    Parameters

    • optB: (() => Option<T>)

      The function to create a fallback optional.

    Returns ((optA) => Option<T>)

    optA or optB.

    Examples

    import { orElse, Option, some, none } from "./option.ts";
    import { assertEquals } from "../deps.ts";

    const nobody = orElse((): Option<string> => none());
    const vikings = orElse((): Option<string> => some("vikings"));

    assertEquals(vikings(some("barbarians")), some("barbarians"));
    assertEquals(vikings(none()), some("vikings"));
    assertEquals(nobody(none()), none());

Generated using TypeDoc