Transforms each side of a Validation with a function, without changing the status of the validation. That is, failures will still be failures, successes will still be successes.
forall a, b, c, d:
(Validation a b).((a) => c, (b) => d) => Validation c d
Transforms each side of a Validation with a function, without changing the status of the validation. That is, failures will still be failures, successes will still be successes.
const Validation = require('folktale/validation');
const upcase = (a) => a.toUpperCase();
const duplicate = (a) => `${a}${a}`;
Validation.Success('a').bimap(duplicate, upcase);
// ==> Validation.Success('A')
Validation.Failure('a').bimap(duplicate, upcase);
// ==> Validation.Failure('aa')
{
/*~*/
Failure: function bimap(failureTransformation, successTransformation) {
assertFunction('Validation.Failure#fold', failureTransformation);
assertFunction('Validation.Failure#fold', successTransformation);
return Failure(failureTransformation(this.value));
},
/*~*/
Success: function bimap(failureTransformation, successTransformation) {
assertFunction('Validation.Success#fold', failureTransformation);
assertFunction('Validation.Success#fold', successTransformation);
return Success(successTransformation(this.value));
}
}