ix
Version:
The Interactive Extensions for JavaScript
37 lines (35 loc) • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generate = void 0;
const iterablex_js_1 = require("./iterablex.js");
class GenerateIterable extends iterablex_js_1.IterableX {
constructor(initialState, condition, iterate, resultSelector) {
super();
this._initialState = initialState;
this._condition = condition;
this._iterate = iterate;
this._resultSelector = resultSelector;
}
*[Symbol.iterator]() {
for (let i = this._initialState; this._condition(i); i = this._iterate(i)) {
yield this._resultSelector(i);
}
}
}
/**
* Generates an iterable sequence by running a state-driven loop producing the sequence's elements.
*
* @template TState The type of the state used in the generator loop.
* @template TResult The type of the elements in the produced sequence.
* @param {TState} initialState The initial state.
* @param {((value: TState) => boolean)} condition Condition to terminate generation (upon returning false).
* @param {((value: TState) => TState)} iterate Iteration step function.
* @param {((value: TState) => TResult)} resultSelector Selector function for results produced in
* the sequence.
* @returns {IterableX<TResult>} The generated iterable sequence.
*/
function generate(initialState, condition, iterate, resultSelector) {
return new GenerateIterable(initialState, condition, iterate, resultSelector);
}
exports.generate = generate;
//# sourceMappingURL=generate.js.map