Of course this example is contrived! It's the simplest example I could think of. I do think it stands for every example of any iterator that takes any input from `.send` or `.throw`. I have plenty of other contrived examples (implementing `fork` like this by using generators for coroutines with promises is at least mildly cool).
That said I absolutely agree that more practical examples are required in order to make this already way-powerful two way protocol into something even more complicated. On Mon, Feb 23, 2015 at 9:11 PM, Brendan Eich <[email protected]> wrote: > Benjamin (Inglor) Gruenbaum wrote: > >> > Why not? The generator would switch on sent value, in a loop. >> >> Well, let's say we have an iterator that does nothing once, returns what >> was sent to it the first 5 times and then is done: >> >> ```js >> function* gen(){ >> var res = yield; >> for(var i = 0; i < 5; i++){ >> res = yield res; >> } >> } >> >> var iter = gen(), res = {}, i = 1; >> iter.next(); >> do { >> res = iter.next(i++); >> console.log(res.value); >> } while(!res.done); >> ``` >> >> How would you clone that with a switch? >> > > The switch has to go on the inside -- the generator author has to > cooperate with client code to make something that can be "cloned". > > It could be this is too great a hardship, but we need more evidence, not > contrived examples. > > /be >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

