On Mon, Feb 23, 2015 at 10:34 AM, Brendan Eich <bren...@mozilla.org> wrote: > Salvador de la Puente González wrote: >> Yep. This was already discussed in the topic I mentioned before. Just to >> remember, the real problem with tee() is that the generators are not >> actually independent as you can not .send() different information to each >> one to make them diverge. > > Why not? The generator would switch on sent value, in a loop.
.tee() "clones" an iterator by caching the values returned by the frontmost iterator, and returning the cached values to the lagging iterators rather than running the master iterator itself. So Salvador is right - you can't .send() different values to a lagging iterator, because the iterator only runs once. To do more sophisticated "cloning", the generator has to cooperate with client code, as you say. It has to be able to serialize out its state at any given yield point, so it can jump-start a fresh "clone" at an arbitrary point and return that, rather than the "fake" cloning that .tee() does. (Not saying anything needs to be added right now. Just pointing out the specifics, as it seemed you were talking past each other.) ~TJ _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss