map

Transforms the value inside a Maybe structure with an unary function. Only transforms values that are successful (Just), and constructs a new Maybe as a result.

Signature

forall a, b: (Maybe a).((a) => b) => Maybe b

Documentation

Transforms the value inside a Maybe structure with an unary function. Only transforms values that are successful (Just), and constructs a new Maybe as a result.

Example:

const Maybe = require('folktale/maybe');

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

Maybe.Just(1).map(increment);
// ==> Maybe.Just(2)

Maybe.Nothing().map(increment);
// ==> Maybe.Nothing()

Properties

Source Code

Defined in source/maybe/maybe.js at line 57, column 18
{
    /*~*/
    Nothing: function map(transformation) {
      assertFunction('Maybe.Nothing#map', transformation);
      return this;
    },

    /*~*/
    Just: function map(transformation) {
      assertFunction('Maybe.Just#map', transformation);
      return Just(transformation(this.value));
    }
  }
Stability
stable
Licence
MIT
Module
folktale/maybe/maybe
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)