fold

Applies a function to each case of a Validation.

Signature

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

Documentation

Applies a function to each case of a Validation.

Example:

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

const upcase = (x) => x.toUpperCase();
const double = (x) => x + x;

Success('a').fold(upcase, double);
// ==> 'aa'

Failure('a').fold(upcase, double);
// ==> 'A'

Properties

Source Code

Defined in source/validation/validation.js at line 70, column 23
{
    /*~*/
    Failure: function fold(failureTransformation, successTransformation) {
      assertFunction('Validation.Failure#fold', failureTransformation);
      assertFunction('Validation.Failure#fold', successTransformation);
      return failureTransformation(this.value);
    },

    /*~*/
    Success: function fold(failureTransformation, successTransformation) {
      assertFunction('Validation.Success#fold', failureTransformation);
      assertFunction('Validation.Success#fold', successTransformation);
      return successTransformation(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/)