Generator use-cases

Jason Orendorff jason.orendorff at
Sun Mar 30 10:58:35 PDT 2008

On Fri, Mar 28, 2008 at 10:32 PM, Brendan Eich <brendan at> wrote:
> This is a long-ish case for including generators in ES4 as proposed.
> [...]

Here's a brief case:  generators let you factor a complex loop,
dividing the value-producing part from the value-consuming part.
Neither part has to be transformed in a non-obvious way.  With
iterators alone, you do this by rewriting the value-producing part as
an Iterator class.  This obfuscates the iterator implementation.

It's hardly news that abstracting from sequences is useful.  Various
languages have had iterators, streams, and lazy lists as core,
essential features (with syntactic support) for decades now.  For
stateful languages, like Python and C#, iterators and generators fill
this gap better than anything else I've seen.

Adobe's position paper commented about generators not being that
useful, because they're not "deep", like full coroutines.  Well, some
people get excited about the coroutine-like uses for generators.  For
me, generators are just the language support you need to use iterators
in your code as the powerful abstraction they ought to be.


More information about the Es4-discuss mailing list