Rewinding iterators
Marcus Stade
marcus at stade.se
Sun Apr 6 17:31:23 PDT 2014
In section 25.1.2 of the
spec<http://wiki.ecmascript.org/lib/exe/fetch.php?id=harmony%3Aspecification_drafts&cache=cache&media=harmony:working_draft_ecma-262_edition_6_04-05-14.pdf>it
says:
The function returns an object that conforms to the IteratorResult
> interface. If a previous call to the next method of an Iterator has
> returned an IteratorResult object whose done property is true, then all
> subsequent calls to the next method of that object must also return an
> IteratorResult object whose done property is true,
>
Are there any practical reasons why the Iterator interface explicitly
disallows this?
It means that, if you care for conformity, you couldn't do something like have
iterators be rewindable <https://gist.github.com/mstade/10012898> or
auto-rewinding
iterators <https://gist.github.com/mstade/10012933>, or any other kind of
iterator that might want to change its state after running it's course
once. This also means, again if you care for conformity, that you have to
keep making new iterator instances. Unless engines start to actively
enforce this, it seems a bit pointless to be that strict.
-- Marcus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140407/9f36f6c0/attachment.html>
More information about the es-discuss
mailing list