Skip to content

Commit

Permalink
Simplify implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobnissen committed Dec 12, 2024
1 parent 6eae199 commit d65ff39
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ using .Base:
AbstractRange, AbstractUnitRange, UnitRange, LinearIndices, TupleOrBottom,
(:), |, +, -, *, !==, !, ==, !=, <=, <, >, >=, =>, missing,
any, _counttuple, eachindex, ntuple, zero, prod, reduce, in, firstindex, lastindex,
tail, fieldtypes, min, max, minimum, zero, oneunit, promote, promote_shape, LazyString,
tuple_type_head, tuple_type_tail
tail, fieldtypes, min, max, minimum, zero, oneunit, promote, promote_shape, LazyString
using Core: @doc

using .Base:
Expand Down Expand Up @@ -1206,21 +1205,10 @@ eltype(::Type{Flatten{I}}) where {I} = eltype(eltype(I))

# For tuples, we statically know the element type of each index, so we can compute
# this at compile time.
eltype(::Type{Flatten{I}}) where {I<:Tuple} = _flatten_eltype(Union{}, I)

function eltype(::Type{Flatten{I}}) where {I<:NamedTuple{<:Any, T}} where T
_flatten_eltype(Union{}, T)
end

function _flatten_eltype(T::Type, I::Type{<:Tuple})
T2 = promote_typejoin(T, eltype(tuple_type_head(I)))
T2 === Any && return Any
_flatten_eltype(T2, tuple_type_tail(I))
function eltype(::Type{Flatten{I}}) where {I<:Union{Tuple,NamedTuple}}
mapreduce(eltype, promote_typejoin, fieldtypes(I); init=Union{})
end

_flatten_eltype(T::Type, I::Type{Tuple{}}) = T

eltype(::Type{Flatten{Tuple{}}}) = eltype(Tuple{})
IteratorEltype(::Type{Flatten{I}}) where {I} = _flatteneltype(I, IteratorEltype(I))
IteratorEltype(::Type{Flatten{Tuple{}}}) = IteratorEltype(Tuple{})
_flatteneltype(I, ::HasEltype) = IteratorEltype(eltype(I))
Expand Down

0 comments on commit d65ff39

Please sign in to comment.