Skip to content

Commit

Permalink
Use Core.Compiler.typesubtract instead of reinventing it poorly
Browse files Browse the repository at this point in the history
  • Loading branch information
galenlynch committed Mar 14, 2019
1 parent 1a07fbc commit e89788a
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions base/skipoftype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ skipoftype(::T, itr) where T = skipoftype(T, itr)

IteratorSize(::Type{<:SkipOfType}) = SizeUnknown()
IteratorEltype(::Type{SkipOfType{T, A}}) where {T, A} = IteratorEltype(A)
eltype(::Type{SkipOfType{T, A}}) where {T, A} = typesubtract(T, eltype(A))
eltype(::Type{SkipOfType{T, A}}) where {T, A} =
Core.Compiler.typesubtract(eltype(A), T)

function iterate(itr::SkipOfType{T, <:Any}, state...) where T
y = iterate(itr.x, state...)
Expand Down Expand Up @@ -137,9 +138,3 @@ mapreduce_impl(f, op, A::SkipOfType, ifirst::Integer, ilast::Integer) =
end
end
end

_typesubtract(::Type{T}, ::Type{Union{T,S}}) where {T, S} = S
_typesubtract(::Type{T}, ::Type{T}) where {T} = Union{}

# Necessary for cases like _typesubtract(Union{A,B}, Union{A,C})
typesubtract(::Type{T}, ::Type{S}) where {T, S} = _typesubtract(T, Union{T,S})

0 comments on commit e89788a

Please sign in to comment.