Applies a function to each case of a Validation.
forall a, b, c:
(Validation a b).((a) => c, (b) => c) => c
Applies a function to each case of a Validation.
const { Success, Failure } = require('folktale/validation');
const upcase = (x) => x.toUpperCase();
const double = (x) => x + x;
Success('a').fold(upcase, double);
// ==> 'aa'
Failure('a').fold(upcase, double);
// ==> 'A'
{
/*~*/
Failure: function fold(failureTransformation, successTransformation) {
assertFunction('Validation.Failure#fold', failureTransformation);
assertFunction('Validation.Failure#fold', successTransformation);
return failureTransformation(this.value);
},
/*~*/
Success: function fold(failureTransformation, successTransformation) {
assertFunction('Validation.Success#fold', failureTransformation);
assertFunction('Validation.Success#fold', successTransformation);
return successTransformation(this.value);
}
}