@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
1 lines • 1.96 kB
Source Map (JSON)
{"version":3,"sources":["iterable/operators/take.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,MAAM,OAAO,YAAsB,SAAQ,SAAkB;IAI3D,YAAY,MAAyB,EAAE,KAAa;QAClD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACpB,IAAI,CAAC,GAAG,CAAC,EAAE;YACT,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;gBAC/B,MAAM,IAAI,CAAC;gBACX,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE;oBACb,MAAM;iBACP;aACF;SACF;IACH,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAU,KAAa;IACzC,OAAO,SAAS,oBAAoB,CAAC,MAAyB;QAC5D,OAAO,IAAI,YAAY,CAAU,MAAM,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC","file":"take.js","sourcesContent":["import { IterableX } from '../iterablex';\nimport { MonoTypeOperatorFunction } from '../../interfaces';\n\nexport class TakeIterable<TSource> extends IterableX<TSource> {\n private _source: Iterable<TSource>;\n private _count: number;\n\n constructor(source: Iterable<TSource>, count: number) {\n super();\n this._source = source;\n this._count = count;\n }\n\n *[Symbol.iterator]() {\n let i = this._count;\n if (i > 0) {\n for (const item of this._source) {\n yield item;\n if (--i === 0) {\n break;\n }\n }\n }\n }\n}\n\n/**\n * Returns a specified number of contiguous elements from the start of an iterable sequence.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @param {number} count The number of elements to return.\n * @returns {MonoTypeOperatorFunction<TSource>} An iterable sequence that contains the specified\n * number of elements from the start of the input sequence.\n */\nexport function take<TSource>(count: number): MonoTypeOperatorFunction<TSource> {\n return function takeOperatorFunction(source: Iterable<TSource>): IterableX<TSource> {\n return new TakeIterable<TSource>(source, count);\n };\n}\n"]}