How to dispatch on Type Vararg?

julia> Type{Vararg}
ERROR: TypeError: in Type, in parameter, expected Type, got Vararg

this seems to be known and explicitly forced

Does someone know an alternative way how I can dispatch on Vararg?
I.e. I have a custom variable type which could be assigned wth Vararg and know I want to dispatch f(type::Type{Vararg}) = ... but this fails with above error.

Any help is highly appreciated

I just found that Tuple{Vararg} isa Type{Tuple{Vararg}}

so using Tuple{Vararg} instead of plain Vararg works already. EDIT: Does no work, see comment below

does not differentiates Vararg as hoped for, because it turns out Tuple{Vararg} == Tuple
someone any idea?

The last parameter of a tuple type can be the special type Vararg, which denotes any number of trailing elements

Doesn’t this imply that there should be non-Vararg arguments at the beginning?
So using solely Vararg seems to be not allowed.


See the interfaces chapter for examples of methods that use Vararg dispatch.

You can use something like

julia> f(::Type{<:Tuple{Vararg}}) = true
f (generic function with 1 method)

julia> f(Tuple{Float64,3}) # example

for dispatch. But I don’t think you can use Vararg in constructing a Type. Perhaps consider NTuple or something similar.

thank you all for your answers. To clarify: The goal is not to dispatch with Vararg, but ON Vararg. My current workaround is to not dispatch at all, but to use if-else. It seems this is the only way possible right now.

type = Vararg
function f(type)
  if type === Vararg
    # do something
    # do something else