Function orElse

  • Like or, but using a function to construct the alternative Maybe.

    Sometimes you need to perform an operation using other data in the environment to construct the fallback value. In these situations, you can pass a function (which may be a closure) as the elseFn to generate the fallback Maybe<T>.

    Useful for transforming empty scenarios based on values in context.

    Type Parameters

    • T

      The type of the wrapped value.

    Parameters

    • elseFn: () => Maybe<T>

      The function to apply if maybe is Nothing

    • maybe: Maybe<T>

      The maybe to use if it is Just.

    Returns Maybe<T>

    The maybe if it is Just, or the Maybe returned by elseFn if the maybe is Nothing.

  • Like or, but using a function to construct the alternative Maybe.

    Sometimes you need to perform an operation using other data in the environment to construct the fallback value. In these situations, you can pass a function (which may be a closure) as the elseFn to generate the fallback Maybe<T>.

    Useful for transforming empty scenarios based on values in context.

    Type Parameters

    • T

      The type of the wrapped value.

    Parameters

    • elseFn: () => Maybe<T>

      The function to apply if maybe is Nothing

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

    The maybe if it is Just, or the Maybe returned by elseFn if the maybe is Nothing.