Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Migrate goog.iter.Iterator #nextValueOrThrow usages to #next calls.
Browse files Browse the repository at this point in the history
RELNOTES: n/a

PiperOrigin-RevId: 432081624
Change-Id: I168995df4f21c64137e27d31f74d0997cc61346d
  • Loading branch information
12wrigja authored and copybara-github committed Mar 3, 2022
1 parent 247f663 commit b1f2691
Showing 1 changed file with 4 additions and 31 deletions.
35 changes: 4 additions & 31 deletions closure/goog/iter/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,48 +57,21 @@ class ShimIterable {
if (iter instanceof ShimIterableImpl || iter instanceof ShimGoogIterator ||
iter instanceof ShimEs6Iterator) {
return iter;
} else if (typeof iter.nextValueOrThrow == 'function') {
} else if (typeof iter.next == 'function') {
return new ShimIterableImpl(
() => wrapGoog(/** @type {!Iterator|!GoogIterator} */ (iter)));
() => /** @type {!Iterator|!GoogIterator} */ (iter));
} else if (typeof iter[Symbol.iterator] == 'function') {
return new ShimIterableImpl(() => iter[Symbol.iterator]());
} else if (typeof iter.__iterator__ == 'function') {
return new ShimIterableImpl(
() => wrapGoog(
/** @type {{__iterator__:function(this:?, boolean=)}} */ (iter)
.__iterator__()));
() => /** @type {{__iterator__:function(this:?, boolean=)}} */ (iter)
.__iterator__());
}
throw new Error('Not an iterator or iterable.');
}
}


/**
* @param {!GoogIterator<VALUE>|!Iterator<VALUE>} iter
* @return {!Iterator<VALUE>}
* @template VALUE
*/
const wrapGoog = (iter) => {
if (!(iter instanceof GoogIterator)) return iter;
let done = false;
return /** @type {?} */ ({
next() {
let value;
while (!done) {
try {
value = /** @type {!GoogIterator<VALUE>} */ (iter).nextValueOrThrow();
break;
} catch (err) {
if (err !== StopIteration) throw err;
done = true;
}
}
return {value, done};
},
});
};


/**
* Concrete (private) implementation of a non-iterator iterable. This is
* separate from the iterator versions since it supports iterables that
Expand Down

0 comments on commit b1f2691

Please sign in to comment.