@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
1 lines • 2.71 kB
Source Map (JSON)
{"version":3,"sources":["asynciterable/operators/takelast.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,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,MAAM,CAAC,GAAG,EAAe,CAAC;YAC1B,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;gBAC5D,IAAI,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE;oBAC3B,CAAC,CAAC,KAAK,EAAE,CAAC;iBACX;gBACD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACd;YAED,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;gBACnB,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":"takelast.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { MonoTypeOperatorAsyncFunction } from '../../interfaces';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\n\nexport class TakeLastAsyncIterable<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 if (this._count > 0) {\n const q = [] as TSource[];\n for await (const item of wrapWithAbort(this._source, signal)) {\n if (q.length >= this._count) {\n q.shift();\n }\n q.push(item);\n }\n\n while (q.length > 0) {\n yield q.shift()!;\n }\n }\n }\n}\n\n/**\n * Returns a specified number of contiguous elements from 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 take from the end of the source sequence.\n * @returns {MonoTypeOperatorAsyncFunction<TSource>} An async-iterable sequence containing the specified\n * number of elements from the end of the source sequence.\n */\nexport function takeLast<TSource>(count: number): MonoTypeOperatorAsyncFunction<TSource> {\n return function takeLastOperatorFunction(\n source: AsyncIterable<TSource>\n ): AsyncIterableX<TSource> {\n return new TakeLastAsyncIterable<TSource>(source, count);\n };\n}\n"]}