# Why no axes(::Tuple)?

**URL:** <https://discourse.julialang.org/t/why-no-axes-tuple/77909>\
**Category:** New to Julia\
**Created:** [March 15, 2022, 10:40am UTC](https://discourse.julialang.org/t/why-no-axes-tuple/77909 "2022-03-15T10:40:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredrikpaues](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikpaues/32/34080_2.png) [@fredrikpaues](https://discourse.julialang.org/u/fredrikpaues)\
**Post date:** [March 15, 2022, 10:40am UTC](https://discourse.julialang.org/t/why-no-axes-tuple/77909/1 "2022-03-15T10:40:18Z")

</div>

Is there a good reason why `axes` ([source](https://github.com/JuliaLang/julia/blob/487757b7557ba8030923261ecf6133cc9d9d5ae6/base/abstractarray.jl#L44)) isn’t defined for tuples? My (perhaps naive) guess was they would be treated much the same as vectors.

(My reason for wondering is that this is what made me implement my own version of `searchsortedlast` that works for tuples in [another question](https://discourse.julialang.org/t/weights-and-indices-for-linear-interpolation-extrapolation/77580/14).)

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [March 15, 2022, 12:11pm UTC](https://discourse.julialang.org/t/why-no-axes-tuple/77909/2 "2022-03-15T12:11:50Z")

</div>

Tuples only have one dimension, so I don’t think `axes` make much sense. Is not `eachindex` good for what you are looking for?

---

<div class="post-metadata">

**Author:** ![fredrikpaues](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikpaues/32/34080_2.png) [@fredrikpaues](https://discourse.julialang.org/u/fredrikpaues)\
**Post date:** [March 15, 2022, 12:51pm UTC](https://discourse.julialang.org/t/why-no-axes-tuple/77909/3 "2022-03-15T12:51:32Z")

</div>

It is. But some functions (such as mentioned `searchsortedlast`) depend on `axes`.

And by that logic `axes(::AbstractVector)` doesn’t make much sense either and yet it is that implementation that `searchsortedlast` rely on 🙂

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [March 15, 2022, 1:31pm UTC](https://discourse.julialang.org/t/why-no-axes-tuple/77909/4 "2022-03-15T13:31:26Z")

</div>

This seems like a bigger reason to change `searchsortedlast` than it does to add `axes(::Tuple)`

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [March 15, 2022, 2:44pm UTC](https://discourse.julialang.org/t/why-no-axes-tuple/77909/5 "2022-03-15T14:44:49Z")

</div>

FWIW here are the docstrings

```julia
axes(A)

  Return the tuple of valid indices for array A.

eachindex(A...)

  Create an iterable object for visiting each index of an AbstractArray A in an efficient manner

```

Both seem to be written keeping arrays in mind, and it’s not clear why one should be preferred for indexing `Tuple`s over the other.

The correct function here seems to be `keys`:

```julia
julia> keys((1,2))
Base.OneTo(2)

```

which has the docstring

```julia
keys(iterator)

  For an iterator or collection that has keys and values (e.g. arrays and dictionaries), return an iterator over the keys.

```

This is more general than `axes`.

---

<div class="post-metadata">

**Author:** ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)\
**Post date:** [March 15, 2022, 7:24pm UTC](https://discourse.julialang.org/t/why-no-axes-tuple/77909/6 "2022-03-15T19:24:17Z")

</div>

To me it seems that `axes` works for tuples.

```julia
julia> a = (1,2,3,4,'a')
(1, 2, 3, 4, 'a')

julia> typeof(a)
Tuple{Int64, Int64, Int64, Int64, Char}

julia> axes(a)
(Base.OneTo(5),)

julia> @which axes(a)
axes(t::Tuple) in Base at tuple.jl:28

```

---

<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:** [March 15, 2022, 7:34pm UTC](https://discourse.julialang.org/t/why-no-axes-tuple/77909/7 "2022-03-15T19:34:06Z")

</div>

Yeah, there’s been a functional `axes(::Tuple)` since Julia v1.1.

---

<div class="post-metadata">

**Author:** ![fredrikpaues](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikpaues/32/34080_2.png) [@fredrikpaues](https://discourse.julialang.org/u/fredrikpaues)\
**Post date:** [March 15, 2022, 8:23pm UTC](https://discourse.julialang.org/t/why-no-axes-tuple/77909/8 "2022-03-15T20:23:52Z")

</div>

I must have done something wrong. Sorry for taking up everybody’s time. It works for me too. I felt sure that I had tested. But I guess that I must have only tested with a tuple in `searchsortedlast`, and that function **isn’t** defined for tuples. I guess that I should submit a pull request on [sort.jl](https://github.com/JuliaLang/julia/blob/master/base/sort.jl) instead.

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [March 16, 2022, 4:12am UTC](https://discourse.julialang.org/t/why-no-axes-tuple/77909/9 "2022-03-16T04:12:12Z")

</div>

Should this be documented? Currently the docstring for `axes` seems to suggest that it’s only for arrays
