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,CAAC;YACpB,CAAC,CAAC,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,EAAE,IAAI,EAAE;YACpD,CAAC,CAAC,EAAE,UAAU,EAAE,oBAAoB,EAAE;QACxC,CAAC,CAAC,oBAAoB,CAAC;IAC3B,OAAO,SAAS,oBAAoB,CAAC,MAAmB;QACtD,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC,CAAC;AACJ,CAAC","file":"scan.js","sourcesContent":["import { IterableX } from '../iterablex';\nimport { OperatorFunction } from '../../interfaces';\nimport { ScanOptions } from './scanoptions';\n\nexport class ScanIterable<T, R> extends IterableX<R> {\n  private _source: Iterable<T>;\n  private _fn: (acc: R, x: T, index: number) => R;\n  private _seed?: T | R;\n  private _hasSeed: boolean;\n\n  constructor(source: Iterable<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  *[Symbol.iterator]() {\n    let i = 0;\n    let hasValue = false;\n    let acc = this._seed;\n    for (const item of this._source) {\n      if (hasValue || (hasValue = this._hasSeed)) {\n        acc = this._fn(<R>acc, item, i++);\n        yield acc;\n      } else {\n        acc = item;\n        hasValue = true;\n        i++;\n      }\n    }\n    if (i === 1 && !this._hasSeed) {\n      yield acc as R;\n    }\n  }\n}\n\n/**\n * Applies an accumulator function over an iterable sequence 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 {OperatorFunction<T, R>} An async-enumerable sequence containing the accumulated values.\n */\nexport function scan<T, R = T>(options: ScanOptions<T, R>): OperatorFunction<T, R>;\nexport function scan<T, R = T>(\n  accumulator: (accumulator: R, current: T, index: number) => R,\n  seed?: R\n): OperatorFunction<T, R>;\nexport function scan<T, R = T>(\n  optionsOrAccumulator: ScanOptions<T, R> | ((accumulator: R, current: T, index: number) => R),\n  seed?: R\n): OperatorFunction<T, R> {\n  const options =\n    // eslint-disable-next-line no-nested-ternary\n    typeof optionsOrAccumulator === 'function'\n      ? arguments.length > 1\n        ? { 'callback': optionsOrAccumulator, 'seed': seed }\n        : { 'callback': optionsOrAccumulator }\n      : optionsOrAccumulator;\n  return function scanOperatorFunction(source: Iterable<T>): IterableX<R> {\n    return new ScanIterable(source, options);\n  };\n}\n"]}