data-forge
Version:
JavaScript data transformation and analysis toolkit inspired by Pandas and LINQ.
48 lines • 1.81 kB
JavaScript
"use strict";
//
// Iterates an underlying iterable in the 'windows'.
//
Object.defineProperty(exports, "__esModule", { value: true });
var series_1 = require("../series");
var SeriesVariableWindowIterator = /** @class */ (function () {
function SeriesVariableWindowIterator(iterable, comparer) {
this.iterator = iterable[Symbol.iterator]();
this.nextValue = this.iterator.next();
this.comparer = comparer;
}
SeriesVariableWindowIterator.prototype.next = function () {
if (this.nextValue.done) {
// Nothing more to read.
// https://github.com/Microsoft/TypeScript/issues/8938
return { done: true }; // <= explicit cast here!;
}
var pairs = [
this.nextValue.value,
];
var prevValue = this.nextValue.value;
// Pull values until there is one that doesn't compare.
// eslint-disable-next-line no-constant-condition
while (true) {
this.nextValue = this.iterator.next();
if (this.nextValue.done) {
break; // No more values.
}
if (!this.comparer(prevValue[1], this.nextValue.value[1])) {
prevValue = this.nextValue.value;
break; // Doesn't compare. Start a new window.
}
pairs.push(this.nextValue.value);
prevValue = this.nextValue.value;
}
var window = new series_1.Series({
pairs: pairs,
});
return {
value: window,
done: false,
};
};
return SeriesVariableWindowIterator;
}());
exports.SeriesVariableWindowIterator = SeriesVariableWindowIterator;
//# sourceMappingURL=series-variable-window-iterator.js.map