Generator use-cases

Kris Zyp kris at
Sat Mar 29 09:37:40 PDT 2008

>> I think Neil's inspiring demonstration of pseudo-threading with 
>> generators
>>  is also worthy of inclusion in your list of generator use cases:
> That code can be written without generators. In general whenever the
> code in the examples from the blog does yield, one can replace that
> with "return function() { the rest of code from the function}". But
> this would require to replace imperative loops from the examples by
> recursive functions.

Of course, but with any flow control (loops, branches, etc.), CPS in JS can 
quickly turn into a ugly and painful exercise. Generators don't provide any 
fundamentally higher level of computability than lambda gave us, but they 
are powerful construct with value. My point was simply to add to the list of 
use cases for generators and throw in my vote for them. I didn't mean to 
detract from Brendan's list.

More information about the Es4-discuss mailing list