>
>
> 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:

https://gist.github.com/zenparsing/26b200543bb8ae0ca4df#file-async-io-4-js

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
of?
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to