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gBACX,QAAQ,GAAG,IAAI,CAAC;aACjB;SACF;IACH,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAW,OAA0B;IAC5D,OAAO,SAAS,yBAAyB,CAAC,MAAwB;QAChE,OAAO,IAAI,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC","file":"scanright.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { toArray } from '../toarray';\nimport { OperatorAsyncFunction } from '../../interfaces';\nimport { ScanOptions } from './scanoptions';\nimport { throwIfAborted } from '../../aborterror';\n\nexport class ScanRightAsyncIterable<T, R> extends AsyncIterableX<R> {\n  private _source: AsyncIterable<T>;\n  private _fn: (acc: R, x: T, index: number, signal?: AbortSignal) => R | Promise<R>;\n  private _seed?: T | R;\n  private _hasSeed: boolean;\n\n  constructor(source: AsyncIterable<T>, options: ScanOptions<T, R>) {\n    super();\n    this._source = source;\n    this._fn = options['callback'];\n    this._hasSeed = options.hasOwnProperty('seed');\n    this._seed = options['seed'];\n  }\n\n  async *[Symbol.asyncIterator](signal?: AbortSignal) {\n    throwIfAborted(signal);\n    let hasValue = false;\n    let acc = this._seed;\n    const source = await toArray(this._source, signal);\n    for (let offset = source.length - 1; offset >= 0; offset--) {\n      const item = source[offset];\n      if (hasValue || (hasValue = this._hasSeed)) {\n        acc = await this._fn(<R>acc, item, offset, signal);\n        yield acc;\n      } else {\n        acc = item;\n        hasValue = true;\n      }\n    }\n  }\n}\n\n/**\n * Applies an accumulator function over an async-iterable sequence from the right and returns each intermediate result.\n * The specified seed value, if given, is used as the initial accumulator value.\n *\n * @export\n * @template T The type of the elements in the source sequence.\n * @template R The type of the result of the aggregation.\n * @param {ScanOptions<T, R>} options The options including the accumulator function and seed.\n * @returns {OperatorAsyncFunction<T, R>} An async-enumerable sequence containing the accumulated values from the right.\n */\nexport function scanRight<T, R = T>(options: ScanOptions<T, R>): OperatorAsyncFunction<T, R> {\n  return function scanRightOperatorFunction(source: AsyncIterable<T>): AsyncIterableX<R> {\n    return new ScanRightAsyncIterable(source, options);\n  };\n}\n"]}