collect

Combines all validation values from an array of them.

This feature is experimental!

This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.

Signature

collect(validations)
forall a, b: (Array (Validation a b)) => Validation a b
where a is Semigroup

Documentation

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.

Example:

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')

Properties

Source Code

Defined in source/validation/collect.js at line 20, column 0
(validations) =>
  validations.reduce((a, b) => a.concat(b), Success())
Stability
experimental
Licence
MIT
Module
folktale/validation/collect
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)