esnext.iterator.find.js 663 B

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