chain

Transforms the value and context of a Validation computation with an unary function. As with .map(), the transformation is only applied if the value is a Success, but the transformation is expected a new Validation value, which then becomes the result of the function.

Signature

chain(validation, fn)
forall a, b, c: (Validation a b, (b) => Validation a c) => Validation a c

Documentation

Transforms the value and context of a Validation computation with an unary function. As with .map(), the transformation is only applied if the value is a Success, but the transformation is expected a new Validation value, which then becomes the result of the function.

Example:

const { Success, Failure, chain } = require('folktale/validation');

chain(Success('a'), x => Success(x.toUpperCase()));
// ==> Success('A')

chain(Success('a'), x => Failure(x));
// ==> Failure('a')

chain(Failure('a'), x => Success(x.toUpperCase()));
// ==> Failure('a')

Properties

Source Code

Defined in source/validation/chain.js at line 17, column 0
(validation, fn) =>
  validation.matchWith({
    Success: ({ value }) => fn(value),
    Failure: ({ value }) => Failure(value)
  })
Stability
stable
Licence
MIT
Module
folktale/validation/chain
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)