UNPKG

data-forge

Version:

JavaScript data transformation and analysis toolkit inspired by Pandas and LINQ.

42 lines 1.56 kB
"use strict"; // // Iterates an underlying iterable in the 'windows'. // Object.defineProperty(exports, "__esModule", { value: true }); var series_1 = require("../series"); var SeriesWindowIterator = /** @class */ (function () { function SeriesWindowIterator(iterable, period, whichIndex) { this.iterable = iterable; this.period = period; this.whichIndex = whichIndex; } SeriesWindowIterator.prototype.next = function () { if (!this.iterator) { this.iterator = this.iterable[Symbol.iterator](); } var curWindow = []; for (var i = 0; i < this.period; ++i) { var curPos = this.iterator.next(); if (curPos.done) { // Underlying iterator is finished. break; } curWindow.push(curPos.value); } if (curWindow.length === 0) { // Underlying iterator doesn't have required number of elements. return { done: true }; } var window = new series_1.Series({ pairs: curWindow }); return { //TODO: The way the index is figured out could have much better performance. value: [this.whichIndex === series_1.WhichIndex.Start ? window.getIndex().first() : window.getIndex().last(), window], done: false, }; }; return SeriesWindowIterator; }()); exports.SeriesWindowIterator = SeriesWindowIterator; //# sourceMappingURL=series-window-iterator.js.map