UNPKG

1.69 kBSource Map (JSON)View Raw
1{"version":3,"sources":["asynciterable/pairwise.ts"],"names":[],"mappings":"AAAA,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;QAC3B,IAAI,KAA0B,EAC5B,QAAQ,GAAG,KAAK,CAAC;QACnB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;YACrC,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;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAU,MAA8B;IAC9D,OAAO,IAAI,qBAAqB,CAAU,MAAM,CAAC,CAAC;AACpD,CAAC","file":"pairwise.js","sourcesContent":["import { AsyncIterableX } from './asynciterablex';\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]() {\n let value: TSource | undefined,\n hasValue = false;\n for await (const item of this._source) {\n if (!hasValue) {\n hasValue = true;\n } else {\n yield [value!, item];\n }\n value = item;\n }\n }\n}\n\n/**\n * Returns a new sequence that triggers on the second and subsequent triggerings of the input sequence.\n * @param {AsyncIterable<T>} source Source sequence.\n * @return {AsyncIterable<T[]>} A sequence that triggers on successive pairs of iterations from the input sequence.\n */\nexport function pairwise<TSource>(source: AsyncIterable<TSource>): AsyncIterableX<TSource[]> {\n return new PairwiseAsyncIterable<TSource>(source);\n}\n"]}
\No newline at end of file