UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

37 lines (35 loc) 977 B
import { IterableX } from '../iterablex'; export class ScanIterable extends IterableX { constructor(source, fn, seed) { super(); this._source = source; this._fn = fn; this._hasSeed = seed.length === 1; this._seed = seed[0]; } *[Symbol.iterator]() { let i = 0; let hasValue = false; let acc = this._seed; for (const item of this._source) { if (hasValue || (hasValue = this._hasSeed)) { acc = this._fn(acc, item, i++); yield acc; } else { acc = item; hasValue = true; i++; } } if (i === 1 && !this._hasSeed) { yield acc; } } } export function scan(accumulator, ...seed) { return function scanOperatorFunction(source) { return new ScanIterable(source, accumulator, seed); }; } //# sourceMappingURL=scan.mjs.map