UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 2.32 kB
{"version":3,"sources":["asynciterable/operators/pairwise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,OAAO,qBAA+B,SAAQ,cAAyB;IAG3E,YAAY,MAA8B;QACxC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QAChD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,KAA0B,CAAC;QAC/B,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;YAC5D,IAAI,CAAC,QAAQ,EAAE;gBACb,QAAQ,GAAG,IAAI,CAAC;aACjB;iBAAM;gBACL,MAAM,CAAC,KAAM,EAAE,IAAI,CAAC,CAAC;aACtB;YACD,KAAK,GAAG,IAAI,CAAC;SACd;IACH,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,SAAS,wBAAwB,CACtC,MAA8B;QAE9B,OAAO,IAAI,qBAAqB,CAAU,MAAM,CAAC,CAAC;IACpD,CAAC,CAAC;AACJ,CAAC","file":"pairwise.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { OperatorAsyncFunction } from '../../interfaces';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\n\nexport class PairwiseAsyncIterable<TSource> extends AsyncIterableX<TSource[]> {\n private _source: AsyncIterable<TSource>;\n\n constructor(source: AsyncIterable<TSource>) {\n super();\n this._source = source;\n }\n\n async *[Symbol.asyncIterator](signal?: AbortSignal) {\n throwIfAborted(signal);\n let value: TSource | undefined;\n let hasValue = false;\n for await (const item of wrapWithAbort(this._source, signal)) {\n if (!hasValue) {\n hasValue = true;\n } else {\n yield [value!, item];\n }\n value = item;\n }\n }\n}\n\n/**\n * Returns a sequence of each element in the input sequence and its predecessor, with the exception of the\n * first element which is only returned as the predecessor of the second element.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @returns {OperatorAsyncFunction<TSource, TSource[]>} The result sequence.\n */\nexport function pairwise<TSource>(): OperatorAsyncFunction<TSource, TSource[]> {\n return function pairwiseOperatorFunction(\n source: AsyncIterable<TSource>\n ): AsyncIterableX<TSource[]> {\n return new PairwiseAsyncIterable<TSource>(source);\n };\n}\n"]}