Extracts the value from a Result
structure.
forall a, b: (Result a b).() => b :: throws TypeError
Extracts the value from a Result
structure.
WARNING
This method is partial, which means that it will only work forOk
structures, not forError
structures. It's recommended to use.getOrElse()
or.matchWith()
instead.
const Result = require('folktale/result');
Result.Ok(1).unsafeGet();
// ==> 1
try {
Result.Error(1).unsafeGet();
// TypeError: Can't extract the value of an Error
} catch (e) {
e instanceof TypeError; // ==> true
}
{
/*~*/
Error: function unsafeGet() {
throw new TypeError(`Can't extract the value of an Error.
Error does not contain a normal value - it contains an error.
You might consider switching from Result#unsafeGet to Result#getOrElse,
or some other method that is not partial.
`);
},
/*~*/
Ok: function unsafeGet() {
return this.value;
}
}