Allows recovering from Failure values with a handler function.
forall a, b, c:
(Validation a b).((a) => Validation c b) => Validation c b
Allows recovering from Failure values with a handler function.
const { Success, Failure } = require('folktale/validation');
Success('a').orElse(e => Success('b'));
// ==> Success('a')
Failure('a').orElse(e => Success('b'));
// ==> Success('b')
Failure('a').orElse(e => Failure('b'));
// ==> Failure('b')
{
/*~*/
Failure: function orElse(handler) {
assertFunction('Validation.Failure#orElse', handler);
return handler(this.value);
},
/*~*/
Success: function orElse(handler) {
assertFunction('Validation.Success#orElse', handler);
return this;
}
}