generators vs forEach

Claus Reinke claus.reinke at talk21.com
Mon Jul 15 08:33:41 PDT 2013


[prompted by this nodejs list thread 
 "Weird error with generators (using suspend or galaxy)"
 https://groups.google.com/forum/#!topic/nodejs/9omOdgSPkz4 ]

1. higher order functions are used to model control structures

2. generators/yield are designed to allow for suspend/resume
    of control structure code

These two statements come in conflict if one considers the restriction
that generators be based on flat continuations, which is sufficient to
span built-in control structures like "for" but not predefined control
structures like "forEach". The support for nested generators ("yield*")
differs from normal function call operation.

I have not seen this conflict discussed here, so I wanted to raise it
in case it was an oversight and something can be done about it. As
far as I can tell, there are two issues:

- current predefined operations like "forEach", "map", "filter", ..
    are not fully integrated with generators, even though they
    model synchronous operations; expecting users to duplicate
    their functionality for use with generators seems wrong;

- is it even possible to define higher-order operations that can be 
    used both normally (without "yield" inside their callbacks, without
    "yield" wrapping their result) and with generators (with "yield"
    inside their callbacks, with "yield" wrapping their result)?

Claus
http://clausreinke.github.com/
 


More information about the es-discuss mailing list