apply

If successes, applies the function in one Validation to another. Otherwise concatenate the failures.

Signature

forall a, b, c: (Validation (b) => c).(Validation a b) => Validation a c

Documentation

If successes, applies the function in one Validation to another. Otherwise concatenate the failures.

Example:

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

Properties

Source Code

Defined in source/validation/validation.js at line 70, column 23
{
    /*~*/
    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);
    }
  }
Licence
MIT
Module
folktale/validation/validation
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)