Transforms the successful value inside a Validation structure with an unary function without changing the status of the validation. That is, Success values continue to be Success values, Failure values continue to be Failure values.
forall a, b, c: (Validation a b).((b) => c) => Validation a c
Transforms the successful value inside a Validation structure with an unary function without changing the status of the validation. That is, Success values continue to be Success values, Failure values continue to be Failure values.
const { Success, Failure } = require('folktale/validation');
const upcase = (a) => a.toUpperCase();
Success('a').map(upcase);
// ==> Success('A')
Failure('a').map(upcase);
// ==> Failure('a')
{
/*~*/
Failure: function map(transformation) {
assertFunction('Validation.Failure#map', transformation);
return this;
},
/*~*/
Success: function map(transformation) {
assertFunction('Validation.Success#map', transformation);
return Success(transformation(this.value));
}
}