Generator use-cases

Igor Bukanov igor at mir2.org
Sat Mar 29 07:40:27 PDT 2008


On 29/03/2008, Kris Zyp <kris at sitepen.com> wrote:
> I think Neil's inspiring demonstration of pseudo-threading with generators
>  is also worthy of inclusion in your list of generator use cases:
>  http://www.neilmix.com/2007/02/07/threading-in-javascript-17/

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.

This shows that if one programs in a functional style, then generators
are not that useful. But they are valuable if the code uses explicit
loops etc. Plus with generators one can assume certain time and space
complexity bounds in ES4 which is not the case for functional code in
the view of deferred tail call proposal.

Regards, Igor



More information about the Es4-discuss mailing list