UNPKG

1.72 kBSource Map (JSON)View Raw
1{"version":3,"sources":["iterable/whiledo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,aAAuB,SAAQ,SAAkB;IAIrD,YAAY,SAAwB,EAAE,MAAyB;QAC7D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,OAAO,IAAI,CAAC,UAAU,EAAE,EAAE;YACxB,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;SACrB;IACH,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,OAAO,CACrB,MAAyB,EACzB,SAAwB;IAExB,OAAO,IAAI,aAAa,CAAU,SAAS,EAAE,MAAM,CAAC,CAAC;AACvD,CAAC","file":"whiledo.js","sourcesContent":["import { IterableX } from './iterablex';\n\nclass WhileIterable<TSource> extends IterableX<TSource> {\n private _condition: () => boolean;\n private _source: Iterable<TSource>;\n\n constructor(condition: () => boolean, source: Iterable<TSource>) {\n super();\n this._condition = condition;\n this._source = source;\n }\n\n *[Symbol.iterator]() {\n while (this._condition()) {\n yield* this._source;\n }\n }\n}\n\n/**\n * Repeats the given source as long as the specified conditions holds, where\n * the condition is evaluated before each repeated source is iterated.\n *\n * @export\n * @template TSource\n * @param {Iterable<TSource>} source Source to repeat as long as the condition function evaluates to true.\n * @param {((signal?: AbortSignal) => boolean)} condition Condition that will be evaluated before the source sequence is iterated.\n * @returns {IterableX<TSource>} An iterable which is repeated while the condition returns true.\n */\nexport function whileDo<TSource>(\n source: Iterable<TSource>,\n condition: () => boolean\n): IterableX<TSource> {\n return new WhileIterable<TSource>(condition, source);\n}\n"]}
\No newline at end of file