I noticed that intersect
on Iterators.ProductIterator{<:NTuple{N,UnitRange}}
generates all the values and stores them in a Vector
. I was expecting it to return an Iterators.ProductIterator{<:NTuple{N,UnitRange}}
since intersect
on UnitRange
returns a UnitRange
.
For instance, the following function
foo(a::Iterators.ProductIterator{<:NTuple{N,UnitRange}}, b::Iterators.ProductIterator{<:NTuple{N,UnitRange}}) where {N} =
Iterators.product(map(intersect, a.iterators, b.iterators)...)
satisfies intersect(a, b) == vec( collect( foo(a, b) ) )
.
I must admit that my usage of Iterators.ProductIterator
is quite limited so perhaps I am overlooking something here?
If not, why not having intersect
of Iterators.ProductIterator{<:NTuple{N,UnitRange}}
return an Iterators.ProductIterator{<:NTuple{N,UnitRange}}
?