UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

15 lines 517 B
import toIterator from './toIterator'; export function reduce(...args) { var _a; if (typeof args[0] === 'function') return it => reduce(it, args[0], args[1]); const it = toIterator(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; } export default reduce; //# sourceMappingURL=reduce.js.map