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AE,EAAE,EAAE,CAAC,IAAI,CAAC;QAEvF,SAAS,QAAQ,CAA6B,GAAG,IAAW;YAC1D,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YACX,IAAI,GAAY,CAAC;YACjB,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;YACtB,IAAI,IAAI,GAAQ,IAAI,CAAC;YACrB,IAAI,IAA6C,CAAC;YAClD,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE;gBACd,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;gBACf,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;oBAC9B,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;iBACpC;qBAAM,IAAI,oBAAoB,CAAC,IAAI,CAAC,EAAE;oBACrC,CAAC,EAAE,GAAG,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;oBACrC,kBAAkB;oBAClB,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAC,GAAG,EAAC,CAAC,CAAC,CAAC;wBAC1D,eAAe,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,EAAC,GAAG,EAAC,CAAC,CAAC;iBAC5E;aACF;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC;CAC3F;AAAC,OAAO,CAAC,EAAE;IACV,KAAK;CACN","file":"asynciterablex.js","sourcesContent":["import { as as asAsyncIterable } from './as';\nimport { _initialize as _initializeFrom } from './from';\nimport { OperatorAsyncFunction, UnaryFunction } from '../interfaces';\nimport { bindCallback } from '../util/bindcallback';\nimport { Observable } from '../observer';\nimport { isReadableNodeStream, isWritableNodeStream } from '../util/isiterable';\n\n/**\n * This class serves as the base for all operations which support [Symbol.asyncIterator].\n */\nexport abstract class AsyncIterableX<T> implements AsyncIterable<T> {\n  abstract [Symbol.asyncIterator](): AsyncIterator<T>;\n\n  async forEach(\n    projection: (value: T, index: number) => void | Promise<void>,\n    thisArg?: any\n  ): Promise<void> {\n    const fn = bindCallback(projection, thisArg, 2);\n    let i = 0;\n    for await (const item of this) {\n      await fn(item, i++);\n    }\n  }\n\n  /** @nocollapse */\n  pipe<R>(...operations: UnaryFunction<AsyncIterable<T>, R>[]): R;\n  pipe<R>(...operations: OperatorAsyncFunction<T, R>[]): AsyncIterableX<R>;\n  pipe<R extends NodeJS.WritableStream>(writable: R, options?: { end?: boolean }): R;\n  pipe<R>(...args: any[]) {\n    let i = -1;\n    const n = args.length;\n    let acc: any = this;\n    while (++i < n) {\n      acc = args[i](asAsyncIterable(acc));\n    }\n    return acc;\n  }\n}\n\n_initializeFrom(AsyncIterableX);\n\nexport type AsyncIterableInput<TSource> =\n  | AsyncIterable<TSource>\n  | AsyncIterator<TSource>\n  | Iterable<TSource | PromiseLike<TSource>>\n  | ArrayLike<TSource>\n  | PromiseLike<TSource>\n  | Observable<TSource>;\n\ntype WritableOrOperatorAsyncFunction<T, R> =\n  | NodeJS.WritableStream\n  | NodeJS.ReadWriteStream\n  | OperatorAsyncFunction<T, R>;\n\ndeclare module '../asynciterable/asynciterablex' {\n  interface AsyncIterableX<T> {\n    pipe(): AsyncIterableX<T>;\n    pipe<A>(op1: OperatorAsyncFunction<T, A>): AsyncIterableX<A>;\n    pipe<A, B>(\n      op1: OperatorAsyncFunction<T, A>,\n      op2: OperatorAsyncFunction<A, B>\n    ): AsyncIterableX<B>;\n    pipe<A, B, C>(\n      op1: OperatorAsyncFunction<T, A>,\n      op2: OperatorAsyncFunction<A, B>,\n      op3: OperatorAsyncFunction<B, C>\n    ): AsyncIterableX<C>;\n    pipe<A, B, C, D>(\n      op1: OperatorAsyncFunction<T, A>,\n      op2: OperatorAsyncFunction<A, B>,\n      op3: OperatorAsyncFunction<B, C>,\n      op4: OperatorAsyncFunction<C, D>\n    ): AsyncIterableX<D>;\n    pipe<A, B, C, D, E>(\n      op1: OperatorAsyncFunction<T, A>,\n      op2: OperatorAsyncFunction<A, B>,\n      op3: OperatorAsyncFunction<B, C>,\n      op4: OperatorAsyncFunction<C, D>,\n      op5: OperatorAsyncFunction<D, E>\n    ): AsyncIterableX<E>;\n    pipe<A, B, C, D, E, F>(\n      op1: OperatorAsyncFunction<T, A>,\n      op2: OperatorAsyncFunction<A, B>,\n      op3: OperatorAsyncFunction<B, C>,\n      op4: OperatorAsyncFunction<C, D>,\n      op5: OperatorAsyncFunction<D, E>,\n      op6: OperatorAsyncFunction<E, F>\n    ): AsyncIterableX<F>;\n    pipe<A, B, C, D, E, F, G>(\n      op1: OperatorAsyncFunction<T, A>,\n      op2: OperatorAsyncFunction<A, B>,\n      op3: OperatorAsyncFunction<B, C>,\n      op4: OperatorAsyncFunction<C, D>,\n      op5: OperatorAsyncFunction<D, E>,\n      op6: OperatorAsyncFunction<E, F>,\n      op7: OperatorAsyncFunction<F, G>\n    ): AsyncIterableX<G>;\n    pipe<A, B, C, D, E, F, G, H>(\n      op1: OperatorAsyncFunction<T, A>,\n      op2: OperatorAsyncFunction<A, B>,\n      op3: OperatorAsyncFunction<B, C>,\n      op4: OperatorAsyncFunction<C, D>,\n      op5: OperatorAsyncFunction<D, E>,\n      op6: OperatorAsyncFunction<E, F>,\n      op7: OperatorAsyncFunction<F, G>,\n      op8: OperatorAsyncFunction<G, H>\n    ): AsyncIterableX<H>;\n    pipe<A, B, C, D, E, F, G, H, I>(\n      op1: OperatorAsyncFunction<T, A>,\n      op2: OperatorAsyncFunction<A, B>,\n      op3: OperatorAsyncFunction<B, C>,\n      op4: OperatorAsyncFunction<C, D>,\n      op5: OperatorAsyncFunction<D, E>,\n      op6: OperatorAsyncFunction<E, F>,\n      op7: OperatorAsyncFunction<F, G>,\n      op8: OperatorAsyncFunction<G, H>,\n      op9: OperatorAsyncFunction<H, I>\n    ): AsyncIterableX<I>;\n    pipe(...operations: OperatorAsyncFunction<any, any>[]): AsyncIterableX<{}>;\n    pipe<A extends NodeJS.WritableStream>(op1: A, options?: { end?: boolean }): A;\n  }\n}\n\ntry {\n  (isBrowser => {\n    if (isBrowser) {\n      return;\n    }\n\n    AsyncIterableX.prototype['pipe'] = nodePipe;\n    const readableOpts = (x: any, opts = x._writableState || { objectMode: true }) => opts;\n\n    function nodePipe<T>(this: AsyncIterableX<T>, ...args: any[]) {\n      let i = -1;\n      let end: boolean;\n      const n = args.length;\n      let prev: any = this;\n      let next: WritableOrOperatorAsyncFunction<T, any>;\n      while (++i < n) {\n        next = args[i];\n        if (typeof next === 'function') {\n          prev = next(asAsyncIterable(prev));\n        } else if (isWritableNodeStream(next)) {\n          ({ end = true } = args[i + 1] || {});\n          // prettier-ignore\n          return isReadableNodeStream(prev) ? prev.pipe(next, {end}) :\n            asAsyncIterable(prev).toNodeStream(readableOpts(next)).pipe(next, {end});\n        }\n      }\n      return prev;\n    }\n  })(typeof window === 'object' && typeof document === 'object' && document.nodeType === 9);\n} catch (e) {\n  /* */\n}\n"]}