Thanks!
On Sunday, July 24, 2016 at 1:52:47 PM UTC+2, jw3126 wrote:
>
> I need a function, which accepts an arbitrary tuple type and returns the
> types of the components of the tuple. For example
> ```
> f(Tuple{Int64, Float64})--> (Int64, Float64)
> f(Tuple{Int64, MyType,
As long as you don't mind preserving exactly what's between the {},
(t.parameters...)
is an easy way to get this.
--Tim
On Sunday, July 24, 2016 5:21:56 AM CDT Kristoffer Carlsson wrote:
> Maybe;
>
> type MyType end
>
> function f(t::DataType)
> I = ()
> for t in t.types
> if isa(t,
El domingo, 24 de julio de 2016, 7:52:47 (UTC-4), jw3126 escribió:
>
> I need a function, which accepts an arbitrary tuple type and returns the
> types of the components of the tuple. For example
> ```
> f(Tuple{Int64, Float64})--> (Int64, Float64)
> f(Tuple{Int64, MyType,
Maybe;
type MyType end
function f(t::DataType)
I = ()
for t in t.types
if isa(t, TypeVar)
I = (I..., Any)
else
I = (I..., t)
end
end
return I
end
julia> f(Tuple{Int64, Float64})
(Int64,Float64)
julia> f(Tuple{Int64, MyType, Float32})
(Int64,MyType,Float32)
julia> f(NTuple{3})
(Any,Any,Any)