UNPKG

970 BJavaScriptView Raw
1import { IterableX } from './iterablex';
2import { toArray } from './toarray';
3export class ScanRightIterable extends IterableX {
4 constructor(source, fn, seed) {
5 super();
6 this._source = source;
7 this._fn = fn;
8 this._hasSeed = seed.length === 1;
9 this._seed = seed[0];
10 }
11 *[Symbol.iterator]() {
12 let hasValue = false, acc = this._seed;
13 const source = toArray(this._source);
14 for (let offset = source.length - 1; offset >= 0; offset--) {
15 const item = source[offset];
16 if (hasValue || (hasValue = this._hasSeed)) {
17 acc = this._fn(acc, item, offset);
18 yield acc;
19 }
20 else {
21 acc = item;
22 hasValue = true;
23 }
24 }
25 }
26}
27export function scanRight(source, accumulator, ...seed) {
28 return new ScanRightIterable(source, accumulator, seed);
29}
30
31//# sourceMappingURL=scanright.mjs.map