fold

Applies a function to each variant of the Maybe structure.

Signature

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

Documentation

Applies a function to each variant of the Maybe structure.

Example:

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

Maybe.Just(1).fold(
  (()  => 'nothing'),
  ((v) => `got ${v}`)
);
// ==> 'got 1'

Maybe.Nothing().fold(
  (()  => 'nothing'),
  ((v) => `got ${v}`)
);
// ==> 'nothing'

Properties

Source Code

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

    /*~*/
    Just: function(transformNothing, transformJust) {
      assertFunction('Maybe.Just#fold', transformNothing);
      assertFunction('Maybe.Just#fold', transformJust);
      return transformJust(this.value);
    }
  }
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/)