UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 3.91 kB
{"version":3,"sources":["iterable/operators/scanright.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAIrC,MAAM,OAAO,iBAAwB,SAAQ,SAAY;IAMvD,YAAY,MAAmB,EAAE,OAA0B;QACzD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC;QACrB,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACrC,KAAK,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE;YAC1D,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5B,IAAI,QAAQ,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE;gBAC1C,GAAG,GAAG,IAAI,CAAC,GAAG,CAAI,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;gBACrC,MAAM,GAAG,CAAC;aACX;iBAAM;gBACL,GAAG,GAAG,IAAI,CAAC;gBACX,QAAQ,GAAG,IAAI,CAAC;aACjB;SACF;IACH,CAAC;CACF;AAiBD,MAAM,UAAU,SAAS,CACvB,oBAA4F,EAC5F,IAAQ;IAER,MAAM,OAAO;IACX,6CAA6C;IAC7C,OAAO,oBAAoB,KAAK,UAAU;QACxC,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,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,yBAAyB,CAAC,MAAmB;QAC3D,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC,CAAC;AACJ,CAAC","file":"scanright.js","sourcesContent":["import { IterableX } from '../iterablex';\nimport { toArray } from '../toarray';\nimport { OperatorFunction } from '../../interfaces';\nimport { ScanOptions } from './scanoptions';\n\nexport class ScanRightIterable<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 hasValue = false;\n let acc = this._seed;\n const source = toArray(this._source);\n for (let offset = source.length - 1; offset >= 0; offset--) {\n const item = source[offset];\n if (hasValue || (hasValue = this._hasSeed)) {\n acc = this._fn(<R>acc, item, offset);\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>): OperatorFunction<T, R>;\nexport function scanRight<T, R = T>(\n accumulator: (accumulator: R, current: T, index: number) => R,\n seed?: R\n): OperatorFunction<T, R>;\nexport function scanRight<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 scanRightOperatorFunction(source: Iterable<T>): IterableX<R> {\n return new ScanRightIterable(source, options);\n };\n}\n"]}