data-forge
Version:
JavaScript data transformation and analysis toolkit inspired by Pandas and LINQ.
40 lines • 1.73 kB
JavaScript
//
// An iterator that produces a contiguous flattened array generated from each set of elements in child iterables.
// Implementation similar to https://docs.scipy.org/doc/numpy/reference/generated/numpy.ravel.html with order 'C'
//
// Note that numpy does not work with arrays of varying lengths. However, the dataforge implementation ignores
// that requirement due to the iterator architecture. Moreover, since the RavelIterator is only used internally
// such cases will not occur.
//
Object.defineProperty(exports, "__esModule", { value: true });
var RavelIterator = /** @class */ (function () {
function RavelIterator(iterables) {
this.iteratorIndex = 0;
this.iterators = iterables.map(function (iterable) { return iterable[Symbol.iterator](); });
}
RavelIterator.prototype.next = function () {
if (this.iterators.length > 0) {
var result = this.iterators[this.iteratorIndex].next();
while (result.done) {
this.iteratorIndex += 1;
if (this.iteratorIndex < this.iterators.length) {
result = this.iterators[this.iteratorIndex].next();
}
else {
// https://github.com/Microsoft/TypeScript/issues/8938
return { done: true }; // <= explicit cast here!;
}
}
return {
done: false,
value: result.value,
};
}
// Return done if empty array passed
return { done: true };
};
return RavelIterator;
}());
exports.RavelIterator = RavelIterator;
//# sourceMappingURL=ravel-iterator.js.map
;