mapError

Transforms the value inside an Error without changing the context of the computation.

Signature

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

Documentation

Transforms the value inside an Error without changing the context of the computation.

This is similar to .map, except it operates on Errors instead of Oks.

Example:

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

Result.Error(1).mapError(x => x + 1);
// ==> Result.Error(2)

Result.Ok(1).mapError(x => x + 1);
// ==> Result.Ok(1)

Properties

Source Code

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

    /*~*/
    Ok: function mapError(f) {
      assertFunction('Result.Ok#mapError', f);
      return this;
    }
  }
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/)