UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 2.46 kB
{"version":3,"sources":["asynciterable/operators/skiplast.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,cAAuB;IAIzE,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,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QAChD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,MAAM,CAAC,GAAG,EAAe,CAAC;QAC1B,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;YAC5D,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACb,IAAI,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE;gBAC1B,MAAM,CAAC,CAAC,KAAK,EAAG,CAAC;aAClB;SACF;IACH,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAU,KAAa;IAC7C,OAAO,SAAS,wBAAwB,CACtC,MAA8B;QAE9B,OAAO,IAAI,qBAAqB,CAAU,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC","file":"skiplast.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { MonoTypeOperatorAsyncFunction } from '../../interfaces';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\n\nexport class SkipLastAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n private _source: AsyncIterable<TSource>;\n private _count: number;\n\n constructor(source: AsyncIterable<TSource>, count: number) {\n super();\n this._source = source;\n this._count = count;\n }\n\n async *[Symbol.asyncIterator](signal?: AbortSignal) {\n throwIfAborted(signal);\n const q = [] as TSource[];\n for await (const item of wrapWithAbort(this._source, signal)) {\n q.push(item);\n if (q.length > this._count) {\n yield q.shift()!;\n }\n }\n }\n}\n\n/**\n * Bypasses a specified number of elements at the end of an async-iterable sequence.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @param {number} count Number of elements to bypass at the end of the source sequence.\n * @returns {MonoTypeOperatorAsyncFunction<TSource>} An async-iterable sequence containing the\n * source sequence elements except for the bypassed ones at the end.\n */\nexport function skipLast<TSource>(count: number): MonoTypeOperatorAsyncFunction<TSource> {\n return function skipLastOperatorFunction(\n source: AsyncIterable<TSource>\n ): AsyncIterableX<TSource> {\n return new SkipLastAsyncIterable<TSource>(source, count);\n };\n}\n"]}