bimap

Transforms each side of a Validation with a function, without changing the status of the validation. That is, failures will still be failures, successes will still be successes.

Signature

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

Documentation

Transforms each side of a Validation with a function, without changing the status of the validation. That is, failures will still be failures, successes will still be successes.

Example:

const Validation = require('folktale/validation');

const upcase = (a) => a.toUpperCase();
const duplicate = (a) => `${a}${a}`;

Validation.Success('a').bimap(duplicate, upcase);
// ==> Validation.Success('A')

Validation.Failure('a').bimap(duplicate, upcase);
// ==> Validation.Failure('aa')

Properties

Source Code

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

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