UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 2.68 kB
{"version":3,"sources":["iterable/operators/flatmap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,MAAM,OAAO,eAAkC,SAAQ,SAAkB;IAKvE,YAAY,MAAyB,EAAE,EAAyC,EAAE,OAAa;QAC7F,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE;YACpC,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE;gBACxE,MAAM,SAAS,CAAC;aACjB;SACF;IACH,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CACrB,QAA+C,EAC/C,OAAa;IAEb,OAAO,SAAS,uBAAuB,CAAC,MAAyB;QAC/D,OAAO,IAAI,eAAe,CAAmB,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC,CAAC;AACJ,CAAC","file":"flatmap.js","sourcesContent":["import { IterableX } from '../iterablex';\nimport { OperatorFunction } from '../../interfaces';\n\nexport class FlatMapIterable<TSource, TResult> extends IterableX<TResult> {\n private _source: Iterable<TSource>;\n private _fn: (value: TSource, index: number) => Iterable<TResult>;\n private _thisArg?: any;\n\n constructor(source: Iterable<TSource>, fn: (value: TSource) => Iterable<TResult>, thisArg?: any) {\n super();\n this._source = source;\n this._fn = fn;\n this._thisArg = thisArg;\n }\n\n *[Symbol.iterator]() {\n let index = 0;\n for (const outerItem of this._source) {\n for (const innerItem of this._fn.call(this._thisArg, outerItem, index++)) {\n yield innerItem;\n }\n }\n }\n}\n\n/**\n * Projects each element of an iterable sequence to an iterable sequence and merges\n * the resulting iterable sequences into one iterable sequence.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @template TResult The type of the elements in the projected inner sequences and the elements in the merged result sequence.\n * @param {((value: TSource, index: number) => Iterable<TResult>)} selector A transform function to apply to each element.\n * @param {*} [thisArg] Option this for binding to the selector.\n * @returns {OperatorFunction<TSource, TResult>} An operator that creates an iterable sequence whose\n * elements are the result of invoking the one-to-many transform function on each element of the input sequence.\n */\nexport function flatMap<TSource, TResult>(\n selector: (value: TSource) => Iterable<TResult>,\n thisArg?: any\n): OperatorFunction<TSource, TResult> {\n return function flatMapOperatorFunction(source: Iterable<TSource>): IterableX<TResult> {\n return new FlatMapIterable<TSource, TResult>(source, selector, thisArg);\n };\n}\n"]}