length() no longer works with Iterators.Stateful in Julia 1.11rc1
In Julia 1.10, the following code works as expected:
julia> length(Iterators.Stateful([1,2,3]))
3
However, in Julia 1.11rc1, the same code fails with this error message:
MethodError: no method matching length(::Base.Iterators.Stateful{Vector{Int64}, Union{Nothing, Tuple{Int64, Int64}}})
This change in behavior appears to be unintended and breaks existing code that relies on being able to get the length of a Stateful iterator.
Steps to reproduce:
- Install Julia 1.11rc1
- Run the code: length(Iterators.Stateful([1,2,3]))
Expected behavior: Returns 3 Actual behavior: MethodError: no method matching length(::Base.Iterators.Stateful{Vector{Int64}, Union{Nothing, Tuple{Int64, Int64}}})
System information:
- Julia version: 1.11rc1
- OS: Linux Mint 21
- Architecture: x86_64
This was a necessary change to do because the previous behavior was incorrect, see #47790.
EDIT: also, please use code blocks in your Markdown.
For such a breaking change the minimum should be that this is mentioned in the documentation. But in my opinion such a breaking change should never happen without a deprecation warning for some time. This is a (in my opinion questionable) change in the API which can break packages like mine and not a "minor change" like the label on the PR #47790 claims.
this is in the appropriate NEWS and HISTORY now