map

Transforms the value inside of a Result structure with an unary function without changing the context of the computation. That is, Error values continue to be Error values, and Ok values continue to be Ok values.

Signature

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

Documentation

Transforms the value inside of a Result structure with an unary function without changing the context of the computation. That is, Error values continue to be Error values, and Ok values continue to be Ok values.

Example:

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

function increment(value) {
  return value + 1;
}

Result.Ok(1).map(increment);
// ==> Result.Ok(2)

Result.Error(1).map(increment);
// ==> Result.Error(1)

Properties

Source Code

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

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