UNPKG

699 BJavaScriptView Raw
1/** @license MIT License (c) copyright 2010-2014 original author or authors */
2/** @author Brian Cavalier */
3/** @author John Hann */
4/** @author Jeff Escalante */
5
6(function(define) { 'use strict';
7define(function() {
8
9 return function fold(Promise) {
10
11 Promise.prototype.fold = function(f, z) {
12 var promise = this._beget();
13
14 this._handler.fold(function(z, x, to) {
15 Promise._handler(z).fold(function(x, z, to) {
16 to.resolve(f.call(this, z, x));
17 }, x, this, to);
18 }, z, promise._handler.receiver, promise._handler);
19
20 return promise;
21 };
22
23 return Promise;
24 };
25
26});
27}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));