Extracts the value from a Just
structure.
forall a: (Maybe a).() => a :: (throws TypeError)
Extracts the value from a Just
structure.
WARNING
This method is partial, which means that it will only work forJust
structures, not forNothing
structures. It's recommended to use.getOrElse()
or.matchWith()
instead.
const Maybe = require('folktale/maybe');
Maybe.Just(1).unsafeGet(); // ==> 1
try {
Maybe.Nothing().unsafeGet();
// TypeError: Can't extract the value of a Nothing
} catch (e) {
e instanceof TypeError; // ==> true
}
{
/*~*/
Nothing: function unsafeGet() {
throw new TypeError(`Can't extract the value of a Nothing.
Since Nothing holds no values, it's not possible to extract one from them.
You might consider switching from Maybe#get to Maybe#getOrElse, or some other method
that is not partial.
`);
},
/*~*/
Just: function unsafeGet() {
return this.value;
}
}