Sha256: 65953357720024ee24caf9af6d295b0456d215b9a8ccb2931bb18b2475615e70

Contents?: true

Size: 1.65 KB

Versions: 13

Compression:

Stored size: 1.65 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/function-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, next, 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);
  }

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

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

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/core-js/internals/iterate.js
tang-0.2.1 spec/tang_app/node_modules/core-js/internals/iterate.js
tang-0.2.0 spec/tang_app/node_modules/core-js/internals/iterate.js
tang-0.1.0 spec/tang_app/node_modules/core-js/internals/iterate.js
tang-0.0.9 spec/tang_app/node_modules/core-js/internals/iterate.js
enju_library-0.3.8 spec/dummy/node_modules/core-js/internals/iterate.js
condenser-0.3 lib/condenser/processors/node_modules/core-js-pure/internals/iterate.js
condenser-0.2 lib/condenser/processors/node_modules/core-js-pure/internals/iterate.js
condenser-0.1 lib/condenser/processors/node_modules/core-js-pure/internals/iterate.js
condenser-0.0.12 lib/condenser/processors/node_modules/core-js-pure/internals/iterate.js
condenser-0.0.11 lib/condenser/processors/node_modules/core-js-pure/internals/iterate.js
condenser-0.0.10 lib/condenser/processors/node_modules/core-js-pure/internals/iterate.js
condenser-0.0.9 lib/condenser/processors/node_modules/core-js-pure/internals/iterate.js