On Feb 2, 2015, at 7:26 AM, Jason Orendorff wrote: > On Sat, Jan 31, 2015 at 10:56 AM, Erik Arvidsson <[email protected]> > wrote: > Another option would be to throw. Then the caller can tell that they did > something that was not expected by the inner iterator. > > > I agree. In fact, isn't this required by transparency? > > Inner().throw() in this situation would throw a TypeError (since there's no > such method). So wrapper().throw() should throw a TypeError.
Except that a consumer (such as for-of) is expected to check for the existence of 'throw' before trying to invoke it. That's really where the transparency is lost in this case. But I agree that throwing to indicate a "protocol violation" seems like a good approach. but it could mean that Inner doesn't get properly "closed". How how about this variation: 2a) An TypeError exception is thrown, but first 'close' (if it is present) is invoked on the yield* target iterator. That would seem to both satisfy the 'close' contract (a consumer (in this case yield*) calls it if is terminating its use of an iterator before the "done" state is reached) and produces an exception to the wrapper consumer for the "throw" protocol violation. Allen > > -j >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

