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M,CAAC,aAAa,CAAC,EAAE,CAAC;IAClF,CAAC;CACF;AAED;;;;;;;GAOG;AACH,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';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\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(\n    source: AsyncIterable<TSource>,\n    depth: number,\n    signal?: AbortSignal\n  ): AsyncIterable<TSource> {\n    if (depth === 0) {\n      for await (const item of wrapWithAbort(source, signal)) {\n        yield item;\n      }\n      return undefined;\n    }\n    for await (const item of wrapWithAbort(source, signal)) {\n      if (isAsyncIterable(item)) {\n        for await (const innerItem of this._flatten(item, depth - 1, signal)) {\n          yield innerItem;\n        }\n      } else {\n        yield item;\n      }\n    }\n  }\n\n  [Symbol.asyncIterator](signal?: AbortSignal) {\n    throwIfAborted(signal);\n    return this._flatten(this._source, this._depth, signal)[Symbol.asyncIterator]();\n  }\n}\n\n/**\n * Flattens the nested async-iterable by the given depth.\n *\n * @export\n * @template T The type of elements in the source sequence.\n * @param {number} [depth=Infinity] The depth to flatten the async-iterable sequence if specified, otherwise infinite.\n * @returns {MonoTypeOperatorAsyncFunction<T>} An operator that flattens the async-iterable sequence.\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"]}