# \`end\` and \`:\` as an argument

**URL:** <https://discourse.julialang.org/t/end-and-as-an-argument/5491>\
**Category:** General Usage\
**Created:** [August 22, 2017, 2:28am UTC](https://discourse.julialang.org/t/end-and-as-an-argument/5491 "2017-08-22T02:28:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Post date:** [August 22, 2017, 2:28am UTC](https://discourse.julialang.org/t/end-and-as-an-argument/5491/1 "2017-08-22T02:28:43Z")

</div>

Is there a way to pass `end` as an argument? For example, when we have a tuple of vectors, we can construct a tuple of the first entries of the vectors as

```julia
julia> t = (rand(2), rand(3), rand(4))
([0.38328, 0.764218], [0.821559, 0.252655, 0.571611], [0.572755, 0.512441, 0.389949, 0.875044])

julia> getindex.(t,1)
(0.38328016631616735, 0.8215592160037497, 0.5727552055080367)

```

I would like to use `end` instead of `1` here to construct a tuple of the last entries of the vectors.

Related, to get the first two entries of the vectors, we can do

```julia
julia> getindex(t, 1:2)
([0.38328, 0.764218], [0.821559, 0.252655, 0.571611])

```

I wonder if there is a way to pass `:` instead of `1:2` to get all the entries of the vectors.

I’m aware that there are many different ways to achieve the aforementioned goals. For example, I can do

```julia
julia> (v->v[end]).(t)
(0.7642183236367728, 0.5716110528720979, 0.8750440080310231)

julia> (v->v[:]).(t)
([0.38328, 0.764218], [0.821559, 0.252655, 0.571611], [0.572755, 0.512441, 0.389949, 0.875044])

```

but I’m just curious if things similar to `getindex.(t,end)` and `getindex.(t, :)` are possible.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 22, 2017, 2:32am UTC](https://discourse.julialang.org/t/end-and-as-an-argument/5491/2 "2017-08-22T02:32:08Z")

</div>

> [@wsshin](#):
>
> I would like to use end instead of 1 here to construct a tuple of the last entries of the vectors.

`getindex.(t,endof.(t))` should do what you want. (`x[end]` is just syntactic sugar for `x[endof(x)]`.)
