bimap

Transforms each side of a Result with a function, without changing the context of the computation. That is, Errors will still be Errors, Oks will still be Oks.

Signature

(Result a b).((a) => c, (b) => d) => Result c d

Documentation

Transforms each side of a Result with a function, without changing the context of the computation. That is, Errors will still be Errors, Oks will still be Oks.

Example:

const Result = require('folktale/result');

const inc = (x) => x + 1;
const dec = (x) => x - 1;


Result.Ok(1).bimap(inc, dec);
// ==> Result.Ok(dec(1))

Result.Error(1).bimap(inc, dec);
// ==> Result.Error(inc(1))

Properties

Source Code

Defined in source/result/result.js at line 75, column 19
{
    /*~*/
    Error: function bimap(f, g) {
      assertFunction('Result.Error#bimap', f);
      assertFunction('Result.Error#bimap', g);
      return Error(f(this.value));
    },

    /*~*/
    Ok: function bimap(f, g) {
      assertFunction('Result.Ok#bimap', f);
      assertFunction('Result.Ok#bimap', g);
      return Ok(g(this.value));
    }
  }
Stability
stable
Licence
MIT
Module
folktale/result/result
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)