esnext.iterator.some.js 616 B

1234567891011121314151617
  1. 'use strict';
  2. // https://github.com/tc39/proposal-iterator-helpers
  3. var $ = require('../internals/export');
  4. var iterate = require('../internals/iterate');
  5. var aCallable = require('../internals/a-callable');
  6. var getIteratorDirect = require('../internals/get-iterator-direct');
  7. $({ target: 'Iterator', proto: true, real: true, forced: true }, {
  8. some: function some(fn) {
  9. var record = getIteratorDirect(this);
  10. var counter = 0;
  11. aCallable(fn);
  12. return iterate(record, function (value, stop) {
  13. if (fn(value, counter++)) return stop();
  14. }, { IS_RECORD: true, INTERRUPTED: true }).stopped;
  15. }
  16. });