That First Next Argument

Kevin Smith zenparsing at
Wed Aug 20 07:41:30 PDT 2014

> This has the disadvantage of starting computation in the generator, of
> course, before it has been asked for.

Thanks Andy.  Creating data sinks (or any general mapping, such as `echo`)
really *are* awkward using the current `x = yield y` model.

The most natural solution I was able to come up with uses a closure
variable to capture the argument to `next` (and `throw` and `return`) and
make it available to the generator:

This makes writing the "echo" iterator much more pleasant:

    const echo = DataSink(input => function*() {
        while (true) yield input.value;

I'm still curious why we need to go through such exercises, though.  It
seems clear to me that this is a weakness of the current design, and would
be easily addressed with syntax.  Is there a back-story that I'm not aware
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list