esnext.iterator.find.js 620 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. find: function find(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(value);
  14. }, { IS_RECORD: true, INTERRUPTED: true }).result;
  15. }
  16. });