-
Notifications
You must be signed in to change notification settings - Fork 21
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
Iterator.drop cannot handle (very) large iterators #13052
Comments
The linked solution just evaluates the underlying iterator, rather than cap the drop count. An iterator wanting different behavior would implement appropriate overrides (such as The current workaround would be to call |
Would this work? val sum = dropping + lo
if (sum < 0) {
dropping = Int.MaxValue
skip()
sum + Int.MaxValue
}
else sum I find it easier to read, but I don't trust myself with 2s-complement arithmetic... |
Simpler is
which has the advantage of forcing less, while still being an easy read. To force least, then skip with dropping at lo - bump, and end with dropping at MaxValue. |
I like the simplest code, even if it forces more than necessary (and I meant to have this discussion in the PL, not here). |
Since it doesn't matter analytically (and if I can convince myself; there is a case for minimal evaluation), I will take your advice and update the PR. It's good to practice simplicity: use it or lose it. |
@scala/collections |
I sometimes use very large iterators (more than
Int.MaxValue
elements) to check that students don't expend in memory when they shouldn't. However, some iterator methods, likedrop
, don't work correctly on those:Interestingly,
++
(concat
) does work:I understand it's a somewhat corner case, but the documentation is silent about such a limitation and the behavior caught me off-guard (especially because
++
worked and things only fell apart when I started usingdrop
). I don't know if this is a documentation issue or if some code needs fixing (maybe just a matter of makingdropping
aLong
in classSliceIterator
).(Note that
Iterator.range(0L, 10_000_000_000L)
also doesn't work, but it's a different issue.)I'm using Scala 3.5.2, but this is a Scala 2 collection problem.
The text was updated successfully, but these errors were encountered: