Permalink
Browse files

(new maybe) Adds .fold to Maybe

  • Loading branch information...
robotlolita committed Mar 5, 2017
1 parent a8f3eef commit 6f59f615c0ac4f09ccef51717eb09b6c669299a6
Showing with 20 additions and 0 deletions.
  1. +20 −0 src/data/maybe/maybe.js
View
@@ -194,6 +194,26 @@ adtMethods(Maybe, {
warnDeprecation('`.cata(pattern)` is deprecated. Use `.matchWith(pattern)` instead.');
return pattern.Just(this.value);
}
},
/*~
* type: |
* forall a, b: (Maybe a).(() => b, (a) => b) => b
*/
fold: {
/*~*/
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);
}
}
});

0 comments on commit 6f59f61

Please sign in to comment.