maybe
if it is a Just
, otherwise defaultMaybe
.
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
maybe
if it is a Just
, otherwise defaultMaybe
.
Provide a fallback for a given
Maybe
. Behaves like a logicalor
: if themaybe
value is aJust
, returns thatmaybe
; otherwise, returns thedefaultMaybe
value.This is useful when you want to make sure that something which takes a
Maybe
always ends up getting aJust
variant, by supplying a default value for the case that you currently have a nothing.