Check out Dart's iterators

Brendan Eich brendan at
Sun Feb 10 00:20:28 PST 2013

This is like C#'s current / moveNext, which was discussed at the May 
2011 TC39 meeting (see ), and then again last September. See


Rehashed Java (hasMore/getNext) and C# (Current/MoveNext) protocols
involving two methods, which costs more for implementors (groups 2 and
3, however ordered) and adds incoherence hazard (two methods get out of
sync; C# tries to mitigate common mistake with Java's, but still has
dual out-of-sync hazard to Java's).

MM agreed with BE that Python's is simplest given other constraints we
can't change, or "least bad".


Changing from hasMore/getNext to current/moveNext does not eliminate two 
methods that can get out of sync. You can imagine one is a property, not 
a method, but the general case is a getter or C#-style Current method.


Domenic Denicola wrote:
> I know `StopIteration` is pretty baked in by now. But, most of the arguments I can recall for it are that it’s better than `hasNext` + `next`, wherein you have to keep two methods in sync. I saw the Dart iterator API the other day and it provided a third alternative I thought the list might enjoy contemplating:
> Translated to ES6, an iterable that counts to 5 it would look like:
> import { current, next } from "@iter";
> let iterable = {
>    [next]() {
>      if (this[current]<  5) {
>        this[current]++;
>      }
>      return this[current]<= 5;
>    },
>    [current]: 0
> };
> That is, `next` does all the work, returning `true`/`false` to signal whether the iteration should proceed. It then keeps `current` in sync with the current value.
> Interesting, if perhaps too late for ES6. I'd of course love to hear why `StopIteration` is better than this, so I can understand and defend it better.
> _______________________________________________
> es-discuss mailing list
> es-discuss at

More information about the es-discuss mailing list