# Compose operator interacting with tuples

**URL:** https://discourse.julialang.org/t/compose-operator-interacting-with-tuples/14916
**Category:** New to Julia
**Created:** [September 13, 2018, 6:14pm UTC](https://discourse.julialang.org/t/compose-operator-interacting-with-tuples/14916 "2018-09-13T18:14:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![fabio-reale](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabio-reale/32/5355_2.png) [@fabio-reale](https://discourse.julialang.org/u/fabio-reale)
#### Post date: [September 13, 2018, 6:14pm UTC](https://discourse.julialang.org/t/compose-operator-interacting-with-tuples/14916/1 "2018-09-13T18:14:42Z")

</div>

My question is: how to best define functions so they compose nicely?

Here is the confusion. The following doesn’t work:

```julia
f(x) = x, x
g(a,b) = a+b

h = g∘f
h(1)

```

This produces a “MethodError: no method matching g(::Tuple{Int64,Int64})”  
It works, however, if I add

```julia
g(xs) = g(xs...)

```

But I don’t really understand why. Much appreciated if someone can help me understand how to better define functions for composition.

---

<div class="post-metadata">

### Author: ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)
#### Post date: [September 13, 2018, 6:36pm UTC](https://discourse.julialang.org/t/compose-operator-interacting-with-tuples/14916/2 "2018-09-13T18:36:49Z")

</div>

The return type of `f` is a tuple:

```julia
julia> typeof(f(1))
Tuple{Int64,Int64}

```

and `g` takes two arguments `a` and `b`. Therefore, `g(f(1))` was undefined because you had not defined a `g` for one argument that does exactly what you implemented by adding another method to `g`: `g(xs)=g(xs...)` splats the tuple into a sequence of arguments.

You could do `g((a,b))=a+b` but i find your above solution more readable 🙂

Cheers!
