Combines all validation values from an array of them.
This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.
forall a, b: (Array (Validation a b)) => Validation a b
where a is Semigroup
Combines all validation values from an array of them.
The function is a convenient way of concatening validations one by one, and will concatenate failures together, but will only maintain the last successful value if they are all successful.
const { Success, Failure, collect } = require('folktale/validation');
collect([
Success('a'),
Success('b'),
Success('c')
]);
// ==> Success('c')
collect([
Failure('a'),
Success('b'),
Failure('c')
]);
// ==> Failure('ac')
collect([
Failure('a'),
Failure('b'),
Failure('c')
]);
// ==> Failure('abc')
(validations) =>
validations.reduce((a, b) => a.concat(b), Success())