# How to programmatically determine the type of a Tuple minus its first parameter?

**URL:** <https://discourse.julialang.org/t/how-to-programmatically-determine-the-type-of-a-tuple-minus-its-first-parameter/12359>\
**Category:** General Usage\
**Created:** [July 13, 2018, 6:30pm UTC](https://discourse.julialang.org/t/how-to-programmatically-determine-the-type-of-a-tuple-minus-its-first-parameter/12359 "2018-07-13T18:30:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![galenlynch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galenlynch/32/17947_2.png) [@galenlynch](https://discourse.julialang.org/u/galenlynch)\
**Post date:** [July 13, 2018, 6:30pm UTC](https://discourse.julialang.org/t/how-to-programmatically-determine-the-type-of-a-tuple-minus-its-first-parameter/12359/1 "2018-07-13T18:30:54Z")

</div>

When working with tuples, you can ‘pop’ the first entry via dispatch as follows:

```julia
tuplepop(t::Tuple{<:Any, Vararg}) = t[2:end]
tuplepop(t::Tuple{}) = t

```

But how can I determine the type of the result ahead of time?

This is the best I can come up with, but it’s hideous:

```julia
tuplepop_type(::Type{T}) where T<:Tuple{<:Any, Vararg} = Tuple{T.parameters[2:end]...}
tuplepop_type(::Type{Tuple{}}) = Tuple{}

```

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 13, 2018, 6:32pm UTC](https://discourse.julialang.org/t/how-to-programmatically-determine-the-type-of-a-tuple-minus-its-first-parameter/12359/2 "2018-07-13T18:32:29Z")

</div>

I’d just use `tuplepop(t::Tuple) = typeof(Base.tail(t))` That’ll error on empty tuples, but you can easily add the `Tuple{}` case as a second method.

---

<div class="post-metadata">

**Author:** ![galenlynch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galenlynch/32/17947_2.png) [@galenlynch](https://discourse.julialang.org/u/galenlynch)\
**Post date:** [July 13, 2018, 6:55pm UTC](https://discourse.julialang.org/t/how-to-programmatically-determine-the-type-of-a-tuple-minus-its-first-parameter/12359/3 "2018-07-13T18:55:59Z")

</div>

Thank you, easy solution!

---

<div class="post-metadata">

**Author:** ![galenlynch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galenlynch/32/17947_2.png) [@galenlynch](https://discourse.julialang.org/u/galenlynch)\
**Post date:** [July 13, 2018, 6:56pm UTC](https://discourse.julialang.org/t/how-to-programmatically-determine-the-type-of-a-tuple-minus-its-first-parameter/12359/4 "2018-07-13T18:56:01Z")

</div>

Oh wait, actually is there some way of determining the return type with only the argument type? It’d be nice to just work with the types.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 13, 2018, 7:29pm UTC](https://discourse.julialang.org/t/how-to-programmatically-determine-the-type-of-a-tuple-minus-its-first-parameter/12359/5 "2018-07-13T19:29:41Z")

</div>

```julia
julia> Base.tuple_type_tail(Tuple{Int,Int,Float64})
Tuple{Int64,Float64}

```

It’s not exported, but it’s better than all other non-exported methods for doing the same.

---

<div class="post-metadata">

**Author:** ![galenlynch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galenlynch/32/17947_2.png) [@galenlynch](https://discourse.julialang.org/u/galenlynch)\
**Post date:** [July 13, 2018, 7:50pm UTC](https://discourse.julialang.org/t/how-to-programmatically-determine-the-type-of-a-tuple-minus-its-first-parameter/12359/6 "2018-07-13T19:50:24Z")

</div>

Thanks! There’s an amazing amount of useful things lurking in Base.

Do you know what Julia’s policy is on non-exported functions in Base? I assume if functions are not exported from Base then there’s no guarantee that they won’t disappear across versions.

---

<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:** [July 14, 2018, 5:56am UTC](https://discourse.julialang.org/t/how-to-programmatically-determine-the-type-of-a-tuple-minus-its-first-parameter/12359/7 "2018-07-14T05:56:59Z")

</div>

They can indeed disappear without deprecations, but at least the maintainers of `Base` do not to introduce different semantics and keep the name, so your unit tests should catch the change and you can rewrite.
