-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Calling Iterators.takewhile(predicate, itr::Stateful)
causes the first non-matching element to be dropped from the Stateful Iterator
#48195
Comments
Also, I'm not actually certain that this particular function is where the change would need to be made. It's possible that the change should be made in the constructor of the |
I took a swing at implementing this in a few different ways, but nothing I did seemed to work. I also referenced Python's Calling Would there be something similar necessary for Julia? |
I agree this is an unfortunate combination of events and just hit it too (I was reading a large Not the end of the world because I can iterate through, |
So this is part of a larger problem in Julia where Base code just assumes all iterators are stateless. This is an assumption that I think we must remove from Base, everywhere we find it. That includes the method of So, given that
|
To me, it's clear that the intended behaviour aught to be that calling
Iterators.takewhile
on a Stateful Iterator should return all leading matching elements, and leave the Stateful Iterator with all remaining elements.One possible solution would be to use
peek
fortakewhile
if the iterator is Stateful, rather thaniterate
as seen here,julia/base/iterators.jl
Lines 856 to 861 in 53a0a69
I'm not certain if this can be applied to the generic implementation as a zero-cost abstraction, or if it would be better handled through multiple dispatch and a more specific method for Stateful Iterators.
I suspect that a similar issue is affecting list comprehensions and Stateful Iterators. I haven't tested that myself, but in my research regarding this issue, I saw several people bringing up a similar complaint.
The text was updated successfully, but these errors were encountered: