Safely get the value out of a Maybe.
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.
Just
defaultValue
Nothing
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!" Copy
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!"
The type of the wrapped value.
The value to return if maybe is a Nothing.
maybe
The Maybe instance to unwrap if it is a Just.
The content of maybe if it is a Just, otherwise defaultValue.
Safely get the value out of a
Maybe
.Returns the content of a
Just
ordefaultValue
ifNothing
. This is the recommended way to get a value out of aMaybe
most of the time.