data-forge
Version:
JavaScript data transformation and analysis toolkit inspired by Pandas and LINQ.
50 lines • 1.94 kB
JavaScript
"use strict";
//
// Iterates an underlying iterable in the 'windows'.
//
Object.defineProperty(exports, "__esModule", { value: true });
var dataframe_1 = require("../dataframe");
var DataFrameVariableWindowIterator = /** @class */ (function () {
function DataFrameVariableWindowIterator(columnNames, iterable, comparer) {
this.columnNames = columnNames;
this.iterator = iterable[Symbol.iterator]();
this.nextValue = this.iterator.next();
this.comparer = comparer;
}
DataFrameVariableWindowIterator.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 dataframe_1.DataFrame({
columnNames: this.columnNames,
pairs: pairs,
});
return {
value: window,
done: false,
};
};
return DataFrameVariableWindowIterator;
}());
exports.DataFrameVariableWindowIterator = DataFrameVariableWindowIterator;
//# sourceMappingURL=dataframe-variable-window-iterator.js.map