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AC,+BAA+B,CAAC,CAAC;KAClD;IAED,OAAO,GAAQ,CAAC;AAClB,CAAC","file":"reduceright.js","sourcesContent":["import { toArray } from './toarray';\nimport { ReduceOptions } from './reduceoptions';\n\n/**\n * Applies an accumulator function over an iterable sequence from the right, returning the result of the aggregation as a\n * single element in the result sequence. The seed value, if specified, is used as the initial accumulator value.\n * For aggregation behavior with incremental intermediate results, scan.\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 {Iterable<T>} source An iterable sequence to aggregate over.\n * @param {ReduceOptions<T, R>} options The options which contains a callback and optional seed.\n * @returns {R} The final accumulator value calculated from the right.\n */\nexport function reduceRight<T, R = T>(source: Iterable<T>, options: ReduceOptions<T, R>): R;\nexport function reduceRight<T, R = T>(\n source: Iterable<T>,\n accumulator: (accumulator: R, current: T, index: number) => R,\n seed?: R\n): R;\nexport function reduceRight<T, R = T>(\n source: Iterable<T>,\n optionsOrAccumulator: ReduceOptions<T, R> | ((accumulator: R, current: T, index: number) => R),\n seed?: R\n): R {\n const options =\n // eslint-disable-next-line no-nested-ternary\n typeof optionsOrAccumulator === 'function'\n ? arguments.length > 2\n ? { 'callback': optionsOrAccumulator, 'seed': seed }\n : { 'callback': optionsOrAccumulator }\n : optionsOrAccumulator;\n const { ['seed']: _seed, ['callback']: callback } = options;\n const hasSeed = options.hasOwnProperty('seed');\n const array = toArray(source);\n let hasValue = false;\n let acc = _seed as T | R;\n for (let offset = array.length - 1; offset >= 0; offset--) {\n const item = array[offset];\n if (hasValue || (hasValue = hasSeed)) {\n acc = callback(<R>acc, item, offset);\n } else {\n acc = item;\n hasValue = true;\n }\n }\n\n if (!(hasSeed || hasValue)) {\n throw new Error('Sequence contains no elements');\n }\n\n return acc as R;\n}\n"]}
\No newline at end of file