using julia 1.1.0 the example taken from the documentation Iteration utilities · The Julia Language works, however while collect works, length throughs an error
julia> collect(Iterators.flatten((1:2, 8:9)))
4-element Array{Int64,1}:
1
2
8
9
julia> length(Iterators.flatten((1:2, 8:9)))
ERROR: ArgumentError: Iterates of the argument to Flatten are not known to have constant length
Stacktrace:
[1] flatten_length(::Base.Iterators.Flatten{Tuple{UnitRange{Int64},UnitRange{Int64}}}, ::Type) at .\iterators.jl:892
[2] length(::Base.Iterators.Flatten{Tuple{UnitRange{Int64},UnitRange{Int64}}}) at .\iterators.jl:894
[3] top-level scope at none:0
Not all Flatten iterators should have their length known,
only if all the iterators being flattened have known length does the overall have known length.
But in your example, that is indeed the case so it should work.
Here is the code from te old version of IterTools for chain, which has now been replaced by flatten in Base.
The question is whether we want length defined when it’s not O(1). See for example this PR which very conservatively added length for a couple of cases where the element type of the flattened iterator are known statically.
For your example of a tuple of ranges, I would say it’s fine to add length as tuples are never too long in practice, but for e.g. Vector{<:Range}, I don’t know. For example we have BitSet with O(n) length, so why not iterators?