Sha256: d6069c6e87b1164e8b1ea8d2adaf01b859e5e303933e9bd25712be6b46b1d272

Contents?: true

Size: 1.58 KB

Versions: 10

Compression:

Stored size: 1.58 KB

Contents

var anObject = require('../internals/an-object');
var isArrayIteratorMethod = require('../internals/is-array-iterator-method');
var toLength = require('../internals/to-length');
var bind = require('../internals/bind-context');
var getIteratorMethod = require('../internals/get-iterator-method');
var callWithSafeIterationClosing = require('../internals/call-with-safe-iteration-closing');

var Result = function (stopped, result) {
  this.stopped = stopped;
  this.result = result;
};

var iterate = module.exports = function (iterable, fn, that, AS_ENTRIES, IS_ITERATOR) {
  var boundFunction = bind(fn, that, AS_ENTRIES ? 2 : 1);
  var iterator, iterFn, index, length, result, step;

  if (IS_ITERATOR) {
    iterator = iterable;
  } else {
    iterFn = getIteratorMethod(iterable);
    if (typeof iterFn != 'function') throw TypeError('Target is not iterable');
    // optimisation for array iterators
    if (isArrayIteratorMethod(iterFn)) {
      for (index = 0, length = toLength(iterable.length); length > index; index++) {
        result = AS_ENTRIES
          ? boundFunction(anObject(step = iterable[index])[0], step[1])
          : boundFunction(iterable[index]);
        if (result && result instanceof Result) return result;
      } return new Result(false);
    }
    iterator = iterFn.call(iterable);
  }

  while (!(step = iterator.next()).done) {
    result = callWithSafeIterationClosing(iterator, boundFunction, step.value, AS_ENTRIES);
    if (result && result instanceof Result) return result;
  } return new Result(false);
};

iterate.stop = function (result) {
  return new Result(true, result);
};

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
condenser-0.0.8 lib/condenser/processors/node_modules/core-js-pure/internals/iterate.js
jester-data-8.0.0 node_modules/core-js/internals/iterate.js
ezii-os-5.2.1 node_modules/core-js/internals/iterate.js
ezii-os-2.0.1 node_modules/core-js/internals/iterate.js
ezii-os-1.1.0 node_modules/core-js/internals/iterate.js
ezii-os-1.0.0 node_modules/core-js/internals/iterate.js
condenser-0.0.7 lib/condenser/processors/node_modules/core-js-pure/internals/iterate.js
ezii-os-0.0.0.1.0 node_modules/core-js/internals/iterate.js
ezii-os-0.0.0.0.1 node_modules/core-js/internals/iterate.js
condenser-0.0.5 lib/condenser/processors/node_modules/core-js-pure/internals/iterate.js