Skip to content

Instantly share code, notes, and snippets.

@TheJaredWilcurt
Created November 26, 2016 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheJaredWilcurt/910f573fef4917d3c6ac498bd858cfca to your computer and use it in GitHub Desktop.
Save TheJaredWilcurt/910f573fef4917d3c6ac498bd858cfca to your computer and use it in GitHub Desktop.
var _marked = [createIterator].map(regeneratorRuntime.mark);
var array = [1, 2, 3];
function createIterator(arr) {
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item;
return regeneratorRuntime.wrap(function createIterator$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context.prev = 3;
_iterator = arr[Symbol.iterator]();
case 5:
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
_context.next = 12;
break;
}
item = _step.value;
_context.next = 9;
return item;
case 9:
_iteratorNormalCompletion = true;
_context.next = 5;
break;
case 12:
_context.next = 18;
break;
case 14:
_context.prev = 14;
_context.t0 = _context["catch"](3);
_didIteratorError = true;
_iteratorError = _context.t0;
case 18:
_context.prev = 18;
_context.prev = 19;
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
case 21:
_context.prev = 21;
if (!_didIteratorError) {
_context.next = 24;
break;
}
throw _iteratorError;
case 24:
return _context.finish(21);
case 25:
return _context.finish(18);
case 26:
case "end":
return _context.stop();
}
}
}, _marked[0], this, [[3, 14, 18, 26], [19,, 21, 25]]);
}
var reference = createIterator(array);
console.log(reference.next()); // { value: 1, done: false }
console.log(reference.next()); // { value: 2, done: false }
console.log(reference.next()); // { value: 3, done: false }
console.log(reference.next()); // { value: undefined, done: true }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment