UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

23 lines (21 loc) 550 B
export function reduce(source, accumulator, ...seed) { const hasSeed = seed.length === 1; let i = 0; let hasValue = false; let acc = seed[0]; for (const item of source) { if (hasValue || (hasValue = hasSeed)) { acc = accumulator(acc, item, i++); } else { acc = item; hasValue = true; i++; } } if (!(hasSeed || hasValue)) { throw new Error('Sequence contains no elements'); } return acc; } //# sourceMappingURL=reduce.mjs.map