• Maps the optional value with a default value init.

    Type Parameters

    • U

    Parameters

    • init: U

      The default value.

    Returns (<T>(f) => ((opt) => U))

    The mapped value or init.

    Examples

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

    const strLenOrAnswer = mapOr(42)((str: string) => str.length);

    assertEquals(strLenOrAnswer(some("Hello, World!")), 13);
    assertEquals(strLenOrAnswer(none()), 42);
      • <T>(f): ((opt) => U)
      • Type Parameters

        • T

        Parameters

        • f: ((t) => U)
            • (t): U
            • Parameters

              • t: T

              Returns U

        Returns ((opt) => U)

          • (opt): U
          • Parameters

            Returns U

Generated using TypeDoc