I want a function taking a type T<:Tuple
type and returning S<:Tuple
type such that T<:S
and the element types are stripped from the input, but with preserved length information.
Desired behavior examples:
f(Tuple{}) == Tuple{}
f(Tuple{Int,String}) == f(Tuple{X,X} where {X<:Number}) == Tuple{Any,Any}
f(Tuple{Int,Vararg{String}}) == Tuple{Any,Vararg}
f(Union{Tuple{Int},Tuple{String}}) == Tuple{Any}
Any ideas for implementing this?
Here’s an approximation:
const Tuple1OrMore = Tuple{Any, Vararg}
const Tuple2OrMore = Tuple{Any,Any, Vararg}
const Tuple3OrMore = Tuple{Any,Any,Any, Vararg}
const Tuple4OrMore = Tuple{Any,Any,Any,Any, Vararg}
const Tuple5OrMore = Tuple{Any,Any,Any,Any,Any,Vararg}
g(::Type{<:Tuple }) = Tuple
g(::Type{<:Tuple1OrMore}) = Tuple1OrMore
g(::Type{<:Tuple2OrMore}) = Tuple2OrMore
g(::Type{<:Tuple3OrMore}) = Tuple3OrMore
g(::Type{<:Tuple4OrMore}) = Tuple4OrMore
g(::Type{<:Tuple5OrMore}) = Tuple5OrMore
f(::Type{T}) where {len, T<:NTuple{len,Any}} = NTuple{len,Any}
f(::Type{T}) where {T<:Tuple} = g(T)
julia> f(Tuple{})
Tuple{}
julia> f(Tuple{Int,String})
Tuple{Any, Any}
julia> f(Tuple{Int,Vararg{String}})
Tuple{Any, Vararg}
julia> f(Union{Tuple{Int},Tuple{String}})
Tuple{Any}