Function or

  • Provide a fallback for a given Maybe. Behaves like a logical or: if the maybe value is a Just, returns that maybe; otherwise, returns the defaultMaybe value.

    This is useful when you want to make sure that something which takes a Maybe always ends up getting a Just variant, by supplying a default value for the case that you currently have a nothing.

    import Maybe from 'true-utils/maybe';

    const justA = Maybe.just("a");
    const justB = Maybe.just("b");
    const aNothing: Maybe<string> = nothing();

    console.log(Maybe.or(justB, justA).toString()); // Just(A)
    console.log(Maybe.or(aNothing, justA).toString()); // Just(A)
    console.log(Maybe.or(justB, aNothing).toString()); // Just(B)
    console.log(Maybe.or(aNothing, aNothing).toString()); // Nothing

    Type Parameters

    • T

    Parameters

    • defaultMaybe: Maybe<T>

      The Maybe to use if maybe is a Nothing.

    • maybe: Maybe<T>

      The Maybe instance to evaluate.

    Returns Maybe<T>

    maybe if it is a Just, otherwise defaultMaybe.

    Typeparam

    T The type of the wrapped value.

  • Type Parameters

    • T

    Parameters

    Returns ((maybe) => Maybe<T>)

Generated using TypeDoc