UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

35 lines (33 loc) 1.09 kB
import { AsyncIterableX } from '../asynciterablex'; import { toArray } from '../toarray'; export class ScanRightAsyncIterable extends AsyncIterableX { constructor(source, fn, seed) { super(); this._source = source; this._fn = fn; this._hasSeed = seed.length === 1; this._seed = seed[0]; } async *[Symbol.asyncIterator]() { let hasValue = false; let acc = this._seed; const source = await toArray(this._source); for (let offset = source.length - 1; offset >= 0; offset--) { const item = source[offset]; if (hasValue || (hasValue = this._hasSeed)) { acc = await this._fn(acc, item, offset); yield acc; } else { acc = item; hasValue = true; } } } } export function scanRight(accumulator, ...seed) { return function scanRightOperatorFunction(source) { return new ScanRightAsyncIterable(source, accumulator, seed); }; } //# sourceMappingURL=scanright.mjs.map