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