You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.by_ref().chunks() consumes one extra element than expected #1035
If I use iter.by_ref().chunks(n) and consume k of the chunks, I expect exactly k*n items to be consumed from iter. But this is not the case as the failing assertion in the following code (playground link) shows:
If the number of chunks to be consumed is known ahead of time then we can use by_ref().take().chunks() as a workaround, but this doesn't work in general.
I suppose this is because the implementation of chunks() wants to reuse the machinery in ChunkBy, but in general ChunkBy really needs access to the next element to know when a chunk ends. I'm not sure what the right solution is.
Activity
ronnodas commentedon Aug 9, 2026
I suppose this is because the implementation of
chunks()wants to reuse the machinery inChunkBy, but in generalChunkByreally needs access to the next element to know when a chunk ends. I'm not sure what the right solution is.