-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed as duplicate of#23431
Closed as duplicate of#23431
Copy link
Labels
iterationInvolves iteration or the iteration protocolInvolves iteration or the iteration protocol
Description
It works for tuples of the same length:
julia> length(Iterators.flatten(((1,2),(3,4))))
4
It fails for arrays of the same or different lengths, tuples of different lengths, and generators of the same length. Here are some errors:
julia> length(Iterators.flatten(([1,2],[3,4])))
ERROR: ArgumentError: Iterates of the argument to Flatten are not known to have constant length
Stacktrace:
[1] flatten_length(f::Base.Iterators.Flatten{Tuple{Vector{Int64}, Vector{Int64}}}, T::Type)
@ Base.Iterators ./iterators.jl:1241
[2] length(f::Base.Iterators.Flatten{Tuple{Vector{Int64}, Vector{Int64}}})
@ Base.Iterators ./iterators.jl:1243
[3] top-level scope
@ REPL[26]:1
julia> length(Iterators.flatten(([1,2],[3])))
ERROR: ArgumentError: Iterates of the argument to Flatten are not known to have constant length
Stacktrace:
[1] flatten_length(f::Base.Iterators.Flatten{Tuple{Vector{Int64}, Vector{Int64}}}, T::Type)
@ Base.Iterators ./iterators.jl:1241
[2] length(f::Base.Iterators.Flatten{Tuple{Vector{Int64}, Vector{Int64}}})
@ Base.Iterators ./iterators.jl:1243
[3] top-level scope
@ REPL[22]:1
julia> length(Iterators.flatten(((1,),(2,3))))
ERROR: ArgumentError: Iterates of the argument to Flatten are not known to have constant length
Stacktrace:
[1] flatten_length(f::Base.Iterators.Flatten{Tuple{Tuple{Int64}, Tuple{Int64, Int64}}}, T::Type)
@ Base.Iterators ./iterators.jl:1241
[2] length(f::Base.Iterators.Flatten{Tuple{Tuple{Int64}, Tuple{Int64, Int64}}})
@ Base.Iterators ./iterators.jl:1243
[3] top-level scope
@ REPL[33]:1
julia> length(Iterators.flatten(((i for i in (1,2)), (i for i in (3,4)))))
ERROR: ArgumentError: Iterates of the argument to Flatten are not known to have constant length
Stacktrace:
[1] flatten_length(f::Base.Iterators.Flatten{Tuple{Base.Generator{…}, Base.Generator{…}}}, T::Type)
@ Base.Iterators ./iterators.jl:1241
[2] length(f::Base.Iterators.Flatten{Tuple{Base.Generator{…}, Base.Generator{…}}})
@ Base.Iterators ./iterators.jl:1243
[3] top-level scope
@ REPL[25]:1
Some type information was truncated. Use `show(err)` to see complete types.
Metadata
Metadata
Assignees
Labels
iterationInvolves iteration or the iteration protocolInvolves iteration or the iteration protocol