Chooses and executes a function for each variant in the Maybe structure.
('a is Variant).({ 'b: (Object Any) => 'c }) => 'c
where 'b = 'a[`@@folktale:adt:tag]
Chooses and executes a function for each variant in the Maybe structure.
const Maybe = require('folktale/maybe');
Maybe.Just(1).matchWith({
Nothing: () => 'nothing',
Just: ({ value }) => `got ${value}`
});
// ==> 'got 1'
Maybe.Nothing().matchWith({
Nothing: () => 'nothing',
Just: ({ value }) => `got ${value}`
});
// ==> 'nothing'
matchWith(pattern) {
return pattern[name](this);
}