# How to dispatch on non-vararg Tuple types

**URL:** <https://discourse.julialang.org/t/how-to-dispatch-on-non-vararg-tuple-types/6656>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 24, 2017, 2:20pm UTC](https://discourse.julialang.org/t/how-to-dispatch-on-non-vararg-tuple-types/6656 "2017-10-24T14:20:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 24, 2017, 2:20pm UTC](https://discourse.julialang.org/t/how-to-dispatch-on-non-vararg-tuple-types/6656/1 "2017-10-24T14:20:44Z")

</div>

Is it possible? What should replace `QUESTION` in the code below?

```julia
f(::Type{QUESTION}) = true
f(Tuple{Int,Int}) # true
f(Tuple{Float64,Vararg{Int}}) # should throw MethodError

```

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [October 24, 2017, 3:03pm UTC](https://discourse.julialang.org/t/how-to-dispatch-on-non-vararg-tuple-types/6656/2 "2017-10-24T15:03:43Z")

</div>

Maybe `f(::Type{NTuple{N,T}}) where {N,T} = true`?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 25, 2017, 6:58am UTC](https://discourse.julialang.org/t/how-to-dispatch-on-non-vararg-tuple-types/6656/3 "2017-10-25T06:58:12Z")

</div>

> [@mauro3](#):
>
> f(::Type{NTuple{N,T}}) where {N,T} = true?

Thanks! This works very nicely as a type alias:

```julia
const TypeFixargTuple = Type{NTuple{N,T}} where {N,T}
f(::TypeFixargTuple) = true
f(::Any) = false

f(Tuple{Int,Int}) # true
f(Tuple{Vararg{Int}}) # false

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 25, 2017, 8:36am UTC](https://discourse.julialang.org/t/how-to-dispatch-on-non-vararg-tuple-types/6656/4 "2017-10-25T08:36:37Z")

</div>

Spoke too soon, the above fails with heterogeneous tuples. But the following works:

```julia
f(::Type{<:NTuple{N,Any}}) where N = true

f(Tuple{Int,Int}) # true
f(Tuple{Int,Char}) # true

```
