julia
6d246dff - Fix length of Iterators.Stateful with underlying mutable iterator (#45924)

Commit
3 years ago
Fix length of Iterators.Stateful with underlying mutable iterator (#45924) Previously, Iterators.Stateful kept track of how many elements have been taken, and reported its length as the length of the underlying iterator minus the number of taken elements. However, this assumes the underlying iterator is immutable. If it is mutable, then the reported length is the same as the number of remaining elements, meaning the wrapper Stateful should not subtract the number of taken elements. After this PR, Stateful instead stores the length of the underlying iterator, if that can be known, and subtracts one every time an element is taken. Hence, the number of remaining elements is being kept track of directly. Fixes #43245 Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Author
Parents
Loading