# Extracing tuple types

**URL:** <https://discourse.julialang.org/t/extracing-tuple-types/23686>\
**Category:** General Usage\
**Created:** [April 30, 2019, 6:46am UTC](https://discourse.julialang.org/t/extracing-tuple-types/23686 "2019-04-30T06:46:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [April 30, 2019, 6:46am UTC](https://discourse.julialang.org/t/extracing-tuple-types/23686/1 "2019-04-30T06:46:42Z")

</div>

Given a tuple, how do I extract the type parameters information? It seems that I can do the following but I’m wondering if there’s a _better_ way i.e. using a public API rather than accessing the `types` or `parameters` field (which seems “private” to me). Similar [post from 1.5 years ago](https://discourse.julialang.org/t/extract-from-tuple-and-verify-fixed-length/6308).

```julia
julia> x = (1, 2, "a", 'c')
(1, 2, "a", 'c')

julia> tx = typeof(x)
Tuple{Int64,Int64,String,Char}

julia> tx.types
svec(Int64, Int64, String, Char)

julia> tx.parameters
svec(Int64, Int64, String, Char)

```

---

<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:** [April 30, 2019, 6:50am UTC](https://discourse.julialang.org/t/extracing-tuple-types/23686/2 "2019-04-30T06:50:20Z")

</div>

```julia
julia> fieldtypes(typeof(x))
(Int64, Int64, String, Char)

```

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [April 30, 2019, 6:55am UTC](https://discourse.julialang.org/t/extracing-tuple-types/23686/3 "2019-04-30T06:55:00Z")

</div>

This is perfect but I’m curious how you figured this out? I tried to find the right function using `methodswith` but did not see anything like this.

---

<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:** [April 30, 2019, 7:24am UTC](https://discourse.julialang.org/t/extracing-tuple-types/23686/4 "2019-04-30T07:24:17Z")

</div>

> [@tk3369](#):
>
> This is perfect but I’m curious how you figured this out?

I was missing this functionality (as you noted in the topic you linked), so I made the PR 😉

> <https://github.com/JuliaLang/julia/pull/29600>
>
> Add \`Base.fieldtypes\`. Cf \`fieldnames\` vs \`fieldname\`.
> 
> Fixes #24312, but is m…ore general. See discussion there.

If you think the discoverability of this is lacking and could be improved, perhaps you should make a PR.

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [April 30, 2019, 8:17am UTC](https://discourse.julialang.org/t/extracing-tuple-types/23686/5 "2019-04-30T08:17:10Z")

</div>

Haha… 😄 That’s great! Thanks a lot for your contribution!
