UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 2.47 kB
{"version":3,"sources":["asynciterable/operators/flat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,MAAM,OAAO,oBAA8B,SAAQ,cAAuB;IAIxE,YAAY,MAA8B,EAAE,KAAa;QACvD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,6CAA6C;IACrC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAA8B,EAAE,KAAa;QACnE,IAAI,KAAK,KAAK,CAAC,EAAE;YACf,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,EAAE;gBAC/B,MAAM,IAAI,CAAC;aACZ;YACD,OAAO,SAAS,CAAC;SAClB;QACD,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,EAAE;YAC/B,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;gBACzB,IAAI,KAAK,EAAE,MAAM,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE;oBAC5D,MAAM,SAAS,CAAC;iBACjB;aACF;iBAAM;gBACL,MAAM,IAAI,CAAC;aACZ;SACF;IACH,CAAC;IAED,CAAC,MAAM,CAAC,aAAa,CAAC;QACpB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;IAC1E,CAAC;CACF;AAED,MAAM,UAAU,IAAI,CAAI,QAAgB,QAAQ;IAC9C,OAAO,SAAS,uBAAuB,CAAC,MAAwB;QAC9D,OAAO,IAAI,oBAAoB,CAAI,MAAM,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC,CAAC;AACJ,CAAC","file":"flat.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { isAsyncIterable } from '../../util/isiterable';\nimport { MonoTypeOperatorAsyncFunction } from '../../interfaces';\n\nexport class FlattenAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n private _source: AsyncIterable<TSource>;\n private _depth: number;\n\n constructor(source: AsyncIterable<TSource>, depth: number) {\n super();\n this._source = source;\n this._depth = depth;\n }\n\n // eslint-disable-next-line consistent-return\n private async *_flatten(source: AsyncIterable<TSource>, depth: number): AsyncIterable<TSource> {\n if (depth === 0) {\n for await (const item of source) {\n yield item;\n }\n return undefined;\n }\n for await (const item of source) {\n if (isAsyncIterable(item)) {\n for await (const innerItem of this._flatten(item, depth - 1)) {\n yield innerItem;\n }\n } else {\n yield item;\n }\n }\n }\n\n [Symbol.asyncIterator]() {\n return this._flatten(this._source, this._depth)[Symbol.asyncIterator]();\n }\n}\n\nexport function flat<T>(depth: number = Infinity): MonoTypeOperatorAsyncFunction<T> {\n return function flattenOperatorFunction(source: AsyncIterable<T>): AsyncIterableX<T> {\n return new FlattenAsyncIterable<T>(source, depth);\n };\n}\n"]}