This method has been replaced by matchWith(pattern)
. cata
(morphism) selects
and executes a function for each variant of the Maybe structure.
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.
forall a, b:
(Maybe a).({
Nothing: () => b,
Just: (a) => b
}) => b
This method has been replaced by matchWith(pattern)
. cata
(morphism) selects
and executes a function for each variant of the Maybe structure.
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'
{
/*~*/
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);
}
}