# Would an AbstractTuple type be helpful?

**URL:** <https://discourse.julialang.org/t/would-an-abstracttuple-type-be-helpful/56673>\
**Category:** Internals & Design\
**Created:** [March 7, 2021, 1:13pm UTC](https://discourse.julialang.org/t/would-an-abstracttuple-type-be-helpful/56673 "2021-03-07T13:13:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [March 7, 2021, 1:13pm UTC](https://discourse.julialang.org/t/would-an-abstracttuple-type-be-helpful/56673/1 "2021-03-07T13:13:04Z")

</div>

Where both `Tuple` and `NamedTuple` are subtypes of `AbstractTuple`.  
Now (v"1.7") that indexing over NamedTuples exists and indexes over its values, there are more methods that share functionality (`first` and `last` have worked alike on both types … for example).

`Tuple` and `NamedTuple` are function-driven types (rather than struct driven); does this make sharing an Abstract type more difficult?

Somewhat related, I have encountered scenarios where being able to group distinct NamedTuple types together and dispatch therewith would be of use.

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [March 7, 2021, 1:40pm UTC](https://discourse.julialang.org/t/would-an-abstracttuple-type-be-helpful/56673/2 "2021-03-07T13:40:32Z")

</div>

`Tuple` is very much special in the type system, because it can have concrete subtypes with a varying number of parameters, is covariant in its parameters and obeys the diagonal rule. This is something that can not be implemented for any other types, therefore I don’t really see the reason for such an abstract type.

If you just want to write code where it’s useful to work with both `Tuple`s and `NamedTuple`s, you can of course use `Union{Tuple, NamedTuple}` or perhaps something like `TupleLike{T <: Tuple} = Union{T, NamedTuple{<:Any, T}` without the need for introducing an abstract type.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [March 7, 2021, 2:05pm UTC](https://discourse.julialang.org/t/would-an-abstracttuple-type-be-helpful/56673/3 "2021-03-07T14:05:34Z")

</div>

persuasive

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [March 7, 2021, 3:29pm UTC](https://discourse.julialang.org/t/would-an-abstracttuple-type-be-helpful/56673/4 "2021-03-07T15:29:33Z")

</div>

`Tuple` and `NamedTuple` don’t share a lot of methods. AFAICT what they have in common is mostly [the basic indexing interface](https://docs.julialang.org/en/v1/manual/interfaces/#Indexing), right? I think we need a trait to identify types that implement it, including also `AbstractArray` and `Broadcasted`.

BTW, in DataFrames.jl we define `DataFrameRow` and `GroupKey` which are views that replicate the behavior of `NamedTuple`. So it could make sense to have an abstract type for named tuple-like types.
