UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

18 lines 637 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reduce = reduce; const toIterator_1 = require("./toIterator"); function reduce(...args) { var _a; if (typeof args[0] === 'function') return it => reduce(it, args[0], args[1]); const it = (0, toIterator_1.default)(args[0]); let next; let accumulator = (_a = args[2]) !== null && _a !== void 0 ? _a : it.next().value; const reducer = args[1]; while (!(next = it.next()).done) accumulator = reducer(accumulator, next.value); return accumulator; } exports.default = reduce; //# sourceMappingURL=reduce.js.map