If successes, applies the function in one Validation to another. Otherwise concatenate the failures.
forall a, b, c: (Validation (b) => c).(Validation a b) => Validation a c
If successes, applies the function in one Validation to another. Otherwise concatenate the failures.
const { Success, Failure } = require('folktale/validation');
const tuple = (a) => (b) => [a, b];
Success(tuple).apply(Success(1)).apply(Success(2));
// ==> Success([1, 2])
Success(tuple).apply(Success(1)).apply(Failure('a'));
// ==> Failure('a')
Success(tuple).apply(Failure('a')).apply(Success(1));
// ==> Failure('a')
Success(tuple).apply(Failure('a')).apply(Failure('b'));
// ==> Failure('ab')
{
/*~*/
Failure: function apply(aValidation) {
assertValidation('Failure#apply', aValidation);
return Failure.hasInstance(aValidation) ? Failure(this.value.concat(aValidation.value))
: /* otherwise */ this;
},
/*~*/
Success: function apply(aValidation) {
assertValidation('Success#apply', aValidation);
return Failure.hasInstance(aValidation) ? aValidation
: /* otherwise */ aValidation.map(this.value);
}
}