PluginProbe
Force Refresh / 2.0.0
Force Refresh v2.0.0
3.2.1 3.2.0 3.1.2 3.1.1 3.1.0 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.12.0 All 54 releases
force-refresh / node_modules / handlebars / node_modules / async / foldl.js

foldl.js in Force Refresh 2.0.0, at node_modules/handlebars/node_modules/async/foldl.js

78 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 'use strict';
2
3 Object.defineProperty(exports, "__esModule", {
4 value: true
5 });
6 exports.default = reduce;
7
8 var _eachOfSeries = require('./eachOfSeries');
9
10 var _eachOfSeries2 = _interopRequireDefault(_eachOfSeries);
11
12 var _noop = require('lodash/noop');
13
14 var _noop2 = _interopRequireDefault(_noop);
15
16 var _once = require('./internal/once');
17
18 var _once2 = _interopRequireDefault(_once);
19
20 var _wrapAsync = require('./internal/wrapAsync');
21
22 var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
23
24 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
26 /**
27 * Reduces `coll` into a single value using an async `iteratee` to return each
28 * successive step. `memo` is the initial state of the reduction. This function
29 * only operates in series.
30 *
31 * For performance reasons, it may make sense to split a call to this function
32 * into a parallel map, and then use the normal `Array.prototype.reduce` on the
33 * results. This function is for situations where each step in the reduction
34 * needs to be async; if you can get the data before reducing it, then it's
35 * probably a good idea to do so.
36 *
37 * @name reduce
38 * @static
39 * @memberOf module:Collections
40 * @method
41 * @alias inject
42 * @alias foldl
43 * @category Collection
44 * @param {Array|Iterable|Object} coll - A collection to iterate over.
45 * @param {*} memo - The initial state of the reduction.
46 * @param {AsyncFunction} iteratee - A function applied to each item in the
47 * array to produce the next step in the reduction.
48 * The `iteratee` should complete with the next state of the reduction.
49 * If the iteratee complete with an error, the reduction is stopped and the
50 * main `callback` is immediately called with the error.
51 * Invoked with (memo, item, callback).
52 * @param {Function} [callback] - A callback which is called after all the
53 * `iteratee` functions have finished. Result is the reduced value. Invoked with
54 * (err, result).
55 * @example
56 *
57 * async.reduce([1,2,3], 0, function(memo, item, callback) {
58 * // pointless async:
59 * process.nextTick(function() {
60 * callback(null, memo + item)
61 * });
62 * }, function(err, result) {
63 * // result is now equal to the last value of memo, which is 6
64 * });
65 */
66 function reduce(coll, memo, iteratee, callback) {
67 callback = (0, _once2.default)(callback || _noop2.default);
68 var _iteratee = (0, _wrapAsync2.default)(iteratee);
69 (0, _eachOfSeries2.default)(coll, function (x, i, callback) {
70 _iteratee(memo, x, function (err, v) {
71 memo = v;
72 callback(err);
73 });
74 }, function (err) {
75 callback(err, memo);
76 });
77 }
78 module.exports = exports['default'];