cata

This method has been replaced by matchWith(pattern). cata(morphism) selects and executes a function for each variant of the Maybe structure.

Deprecated since 2.0.0

The cata(morphism) terminology is not very welcoming for people who are not familiar with some obscure jargon in functional programming. In addition to that, due to the design of Folktale's 2 union constructor, it's not possible to provide the same interface as Folktale 1's .cata() method, so changing the name while deprecating the old functionality allows people to move to Folktale 2 without breaking their code.

Signature

forall a, b:
  (Maybe a).({
    Nothing: () => b,
    Just: (a) => b
  }) => b

Documentation

This method has been replaced by matchWith(pattern). cata(morphism) selects and executes a function for each variant of the Maybe structure.

Example:

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

Maybe.Just(1).cata({
  Nothing: ()   => 'nothing',
  Just: (value) => `got ${value}`
});
// ==> 'got 1'

Maybe.Nothing().cata({
  Nothing: ()   => 'nothing',
  Just: (value) => `got ${value}`
});
// ==> 'nothing'

Properties

Source Code

Defined in source/maybe/maybe.js at line 57, column 18
{
    /*~*/
    Nothing: function cata(pattern) {
      warnDeprecation('`.cata(pattern)` is deprecated. Use `.matchWith(pattern)` instead.');
      return pattern.Nothing();
    },

    /*~*/
    Just: function cata(pattern) {
      warnDeprecation('`.cata(pattern)` is deprecated. Use `.matchWith(pattern)` instead.');
      return pattern.Just(this.value);
    }
  }
Stability
deprecated
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/)