fold.js 699 B

123456789101112131415161718192021222324252627
  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. (function(define) { 'use strict';
  6. define(function() {
  7. return function fold(Promise) {
  8. Promise.prototype.fold = function(f, z) {
  9. var promise = this._beget();
  10. this._handler.fold(function(z, x, to) {
  11. Promise._handler(z).fold(function(x, z, to) {
  12. to.resolve(f.call(this, z, x));
  13. }, x, this, to);
  14. }, z, promise._handler.receiver, promise._handler);
  15. return promise;
  16. };
  17. return Promise;
  18. };
  19. });
  20. }(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); }));