External: Iterator

Iterator

An occurrence of a Generator.

This is the result of calling a generator function which does yield on each item it wants to expose. It can actually be a hand made object as long as it respects the contract of this interface.

Source:
See:

Examples

function* generator() {
  yield 1;
  yield 2;
  yield 3;
}
var it = generator();
var it = (function () {
  var i = 0;
  var content = [1, 2, 3];
  return {
    next : function () {
      var res;
      if (i < content.length) {
        res = { done : false, value : content[i] };
      } else {
        res = { done : true };
      }
      i++;
      return res;
    }
  };
})();

Methods

next()

Reads the next item on the iterator.

Can either return a value if it is not done, { done : false, value : 'some value' }, or inform it is done with { done : true }.

Source:
Returns:
Object a done marker or a value container.