esnext.iterator.some.js 729 B

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