Function: unwrapOr()
Call Signature
unwrapOr<
T,U>(defaultValue,maybe):T|U
Safely get the value out of a Maybe.
Returns the content of a Just or defaultValue if Nothing. This is the recommended way to get a value out of a Maybe most of the time.
import Maybe from 'true-myth/maybe';
const notAString = Maybe.nothing<string>();
const isAString = Maybe.just('look ma! some characters!');
console.log(Maybe.unwrapOr('<empty>', notAString)); // "<empty>"
console.log(Maybe.unwrapOr('<empty>', isAString)); // "look ma! some characters!"Type Parameters
T
T extends object
The type of the wrapped value.
U
U
Parameters
defaultValue
U
The value to return if maybe is a Nothing.
maybe
Maybe<T>
The Maybe instance to unwrap if it is a Just.
Returns
T | U
The content of maybe if it is a Just, otherwise defaultValue.
Call Signature
unwrapOr<
T,U>(defaultValue): (maybe) =>T|U
Safely get the value out of a Maybe.
Returns the content of a Just or defaultValue if Nothing. This is the recommended way to get a value out of a Maybe most of the time.
import Maybe from 'true-myth/maybe';
const notAString = Maybe.nothing<string>();
const isAString = Maybe.just('look ma! some characters!');
console.log(Maybe.unwrapOr('<empty>', notAString)); // "<empty>"
console.log(Maybe.unwrapOr('<empty>', isAString)); // "look ma! some characters!"Type Parameters
T
T extends object
The type of the wrapped value.
U
U
Parameters
defaultValue
U
The value to return if maybe is a Nothing.
Returns
The content of maybe if it is a Just, otherwise defaultValue.
(
maybe):T|U
Parameters
maybe
Maybe<T>
Returns
T | U