foldr.js
 1  'use strict';
 2  
 3  Object.defineProperty(exports, "__esModule", {
 4    value: true
 5  });
 6  exports.default = reduceRight;
 7  
 8  var _reduce = require('./reduce');
 9  
10  var _reduce2 = _interopRequireDefault(_reduce);
11  
12  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13  
14  /**
15   * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order.
16   *
17   * @name reduceRight
18   * @static
19   * @memberOf module:Collections
20   * @method
21   * @see [async.reduce]{@link module:Collections.reduce}
22   * @alias foldr
23   * @category Collection
24   * @param {Array} array - A collection to iterate over.
25   * @param {*} memo - The initial state of the reduction.
26   * @param {AsyncFunction} iteratee - A function applied to each item in the
27   * array to produce the next step in the reduction.
28   * The `iteratee` should complete with the next state of the reduction.
29   * If the iteratee complete with an error, the reduction is stopped and the
30   * main `callback` is immediately called with the error.
31   * Invoked with (memo, item, callback).
32   * @param {Function} [callback] - A callback which is called after all the
33   * `iteratee` functions have finished. Result is the reduced value. Invoked with
34   * (err, result).
35   * @returns {Promise} a promise, if no callback is passed
36   */
37  function reduceRight(array, memo, iteratee, callback) {
38    var reversed = [...array].reverse();
39    return (0, _reduce2.default)(reversed, memo, iteratee, callback);
40  }
41  module.exports = exports['default'];