-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can you tee multiple times #134
Comments
You cannot do If the input iterable is an iterator [or generator], then it must be discarded [read not touched] by the caller after calling tee. So in a sense Other than that, Regarding memory leak. The current implementation keeps a copy of each yielded element for as long as needed but not more. As long as needed here means that if you consume each copy in "parallel" then constant additional space will be used for storage. On the other hand, if you keep an unconsumed copy somewhere then a single copy of each element will be kept in memory (linear additional space) until that last unconsumed copy gets garbage collected. Does that answer your question? |
yeah that's what I was afraid of, I want to tee multiple times an iterator that is not guaranteed to end, but I suppose easier is to simply, copy the information in an array as soon as it's read, and operate from there, instead of merely teeing multiple times, thanks. |
Yep. That's a solution! Keeping a copy of the data read so far is definitely the only solution if you do not know in advance how many times you will have to let source = ...; // can be infinite
let copy1, copy2, copy3, copy4, copy5, ...; // as many as you like
[source, copy1, copy2] = tee(source, 3);
...
[source, copy3, copy4, copy5] = tee(source, 4);
... // etc Note the important bit where |
PS: Actually, in the example given above, if you consume any of |
without fear of a memory leak, or is this simply the wrong way of doing things?
The text was updated successfully, but these errors were encountered: