# Unpacking tuples in function call

**URL:** <https://discourse.julialang.org/t/unpacking-tuples-in-function-call/25771>\
**Category:** General Usage\
**Created:** [June 27, 2019, 4:42pm UTC](https://discourse.julialang.org/t/unpacking-tuples-in-function-call/25771 "2019-06-27T16:42:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dataDiver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datadiver/32/8174_2.png) [@dataDiver](https://discourse.julialang.org/u/dataDiver)\
**Post date:** [June 27, 2019, 4:42pm UTC](https://discourse.julialang.org/t/unpacking-tuples-in-function-call/25771/1 "2019-06-27T16:42:11Z")

</div>

This is not a help request more of a pleasant observation. I was working with tuples and needed to create a function where the tuples would be unpacked and used separately, something like:

```julia
function myFun(x::Int64, y::Float64)
  println("Do something with x: $x")
  println("Do something else with y: $y")
end

# Call it like this:
tp = (42, 3.1459)
myFun(tp[1], tp[2])

```

Then I though I’d look really silly if I could have done something like this instead:

```julia
function myFun((x, y)::Tuple{Int64, Float64})
  println("Do something with x: $x")
  println("Do something else with y: $y")
end

# Then call it like this:
myFun(tp)

```

I tried it and it worked! That’s awesome!

---

<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:** [June 27, 2019, 9:06pm UTC](https://discourse.julialang.org/t/unpacking-tuples-in-function-call/25771/2 "2019-06-27T21:06:53Z")

</div>

Yup, it’s great! It’s also a pretty new feature (as of v0.7/1.0: [https://github.com/JuliaLang/julia/blob/master/HISTORY.md#new-language-features-2](https://github.com/JuliaLang/julia/blob/master/HISTORY.md#new-language-features-2))

---

<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:** [June 28, 2019, 12:12pm UTC](https://discourse.julialang.org/t/unpacking-tuples-in-function-call/25771/3 "2019-06-28T12:12:25Z")

</div>

> [@dataDiver](#):
>
> ```julia
> function myFun((x, y)::Tuple{Int64, Float64})
> 
> ```

I was very excited by being able to dispatch on `Tuple` (and, in a very similar way, `NamedTuple`) types the same time I decompose them, but in practice it lead to poor coding style for me. YMMV.
