pop-iterate
Version:
A polymorphic iterate operator for arrays and other iterables
24 lines (19 loc) • 598 B
JavaScript
var Iteration = require("./iteration");
module.exports = ArrayIterator;
function ArrayIterator(iterable, start, stop, step) {
this.array = iterable;
this.start = start || 0;
this.stop = stop || Infinity;
this.step = step || 1;
}
ArrayIterator.prototype.next = function () {
var iteration;
if (this.start < Math.min(this.array.length, this.stop)) {
iteration = new Iteration(this.array[this.start], false, this.start);
this.start += this.step;
} else {
iteration = new Iteration(undefined, true);
}
return iteration;
};
;