iterator-indexed.js 630 B

123456789101112131415161718
  1. 'use strict';
  2. // https://github.com/tc39/proposal-iterator-helpers
  3. var call = require('../internals/function-call');
  4. var anObject = require('../internals/an-object');
  5. var getIteratorDirect = require('../internals/get-iterator-direct');
  6. var createIteratorProxy = require('../internals/iterator-create-proxy');
  7. var IteratorProxy = createIteratorProxy(function () {
  8. var result = anObject(call(this.next, this.iterator));
  9. var done = this.done = !!result.done;
  10. if (!done) return [this.index++, result.value];
  11. });
  12. module.exports = function indexed() {
  13. return new IteratorProxy(getIteratorDirect(this), {
  14. index: 0
  15. });
  16. };