Terry Reedy wrote:
As I understand, everything goes into the tee and everything comes out in order, so I don't understand what you mean keeping some value.
itertools.tee() knows where each of the spawned iterators is up to in the sequence so it knows when it can throw away old values. In the degenerate case (such as your cartesian product example) it has to store the whole series in memory but it can usually do better than that (based on how far apart the spawned iterators get).
I believe someone else though it was too simple for the stdlib ;-) The solution is a variation of functools.partial.
Approaching it as a variant of functools.partial certainly sounds like the way to go (and rereading your initial post, I realise you have indeed been doing that all along).
It will be interesting to see what your search for concrete use cases turns up.