UNPKG

629 BJavaScriptView Raw
1import { IterableX } from './iterablex';
2class DeferIterable extends IterableX {
3 constructor(fn) {
4 super();
5 this._fn = fn;
6 }
7 *[Symbol.iterator]() {
8 for (const item of this._fn()) {
9 yield item;
10 }
11 }
12}
13/**
14 * Creates an enumerable sequence based on an iterable factory function.
15 * @param {function(): Iterable<T>} factory Iterable factory function.
16 * @return {Iterable<T>} Sequence that will invoke the iterable factory upon a call to [Symbol.iterator]().
17 */
18export function defer(factory) {
19 return new DeferIterable(factory);
20}
21
22//# sourceMappingURL=defer.mjs.map