apply

Transforms a Maybe value using a function contained in another Maybe. As with .map(), the Maybe values are expected to be Just, and no operation is performed if any of them is a Nothing.

Signature

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

Documentation

Transforms a Maybe value using a function contained in another Maybe. As with .map(), the Maybe values are expected to be Just, and no operation is performed if any of them is a Nothing.

Example:

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

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

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

Maybe.Just(increment).apply(Maybe.Nothing());
// ==> Maybe.Nothing()

Maybe.Nothing().apply(Maybe.Just(1));
// ==> Maybe.Nothing()

Properties

Source Code

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

    /*~*/
    Just: function apply(aMaybe) {
      assertMaybe('Maybe.Just#apply', aMaybe);
      return aMaybe.map(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/)