# Is there a way to "forward" getindex for Tuples in a type-stable way?

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-forward-getindex-for-tuples-in-a-type-stable-way/2889>\
**Category:** General Usage\
**Created:** [March 26, 2017, 10:48pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-forward-getindex-for-tuples-in-a-type-stable-way/2889 "2017-03-26T22:48:24Z")\
**Posts on this page:** 1\
**Showing post:** 20

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [September 17, 2017, 8:18pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-forward-getindex-for-tuples-in-a-type-stable-way/2889/20 "2017-09-17T20:18:39Z")

</div>

It’s not directly possible, since there’s no way for the compiler to know the type of each element if you’re just iterating through them in a loop. But there are a lot of other options to make this work:

- [Unrolled.jl](https://github.com/cstjean/Unrolled.jl)
- [ArrayPartition](https://github.com/JuliaDiffEq/RecursiveArrayTools.jl#arraypartition)
- [TypeSortedCollections.jl](https://github.com/tkoolen/TypeSortedCollections.jl)
- Lisp-y tuple recursion like in [Type stability when arguments are functions - #4 by tim.holy](https://discourse.julialang.org/t/type-stability-when-arguments-are-functions/4734/4)

(this isn’t specific to having a wrapper around a tuple–you’ll have the same issues with regular Julia tuples too). All of these make it possible to call a function on a mixture of types in an inferable way, without necessarily implementing a type-stable getindex().

Another option would be to store [FunctionWrappers](https://github.com/yuyichao/FunctionWrappers.jl) instead of the objects themselves in order to create a concretely-typed collection.

---

_[View the full topic](https://discourse.julialang.org/t/is-there-a-way-to-forward-getindex-for-tuples-in-a-type-stable-way/2889)._
