Allen Wirfs-Brock (2013-05-13T18:57:43.000Z)
github at esdiscuss.org (2013-07-12T02:27:20.735Z)
On May 13, 2013, at 11:08 AM, Andreas Rossberg wrote: > See my previous reply. I think there is some confusion here about the > direction of the abstraction. Likewise, but I won't argue it again as I think we are converging upon a fine solution. > Exactly. But iterators don't currently have `send` and `throw` > methods. So you would want to do something different for > generator-like objects then you'd do for other iterators. Or align the interfaces so that the differences don't exist for the situations when the two abstractions are reasonable alternatives. > The case I was talking about is simply this: > > ```js > function* g() { > yield* [1, 2] > } > > var o = g() > o.send(undefined) > o.send(5) // what does this mean? > ``` > > But I suppose the answer is that the sent value is just dropped on the > floor, as per the iterator expression interpretation you gave in the > other post. Makes sense, I guess. Right. whenever you "send" a value back to a generator you are doing something that requires specific and specialized understanding of the "receiver". If you are sending to an arbitrary generator/iterator you should have no expectation other than the the value is likely to be dropped on the floor,. > I happen to dislike the name `send` a lot and would rather call it > `resume`. ;) But your suggestion of merging it with `next` sounds > plausible as well. +1 (myself, really :-) > That might actually work. If we manage to truly unify iterator and > generator types then you got me convinced. Which? The abstract class or the guarded `throw` in `yield*` (or both). I think if we can unify all of this we will have simplified the language in a way that will benefit many users for a long time to come.