# Is there a way to distribute an array to different argument positions in a function?

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-distribute-an-array-to-different-argument-positions-in-a-function/45616>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [August 27, 2020, 8:58am UTC](https://discourse.julialang.org/t/is-there-a-way-to-distribute-an-array-to-different-argument-positions-in-a-function/45616 "2020-08-27T08:58:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujunyan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sujunyan/32/30768_2.png) [@sujunyan](https://discourse.julialang.org/u/sujunyan)\
**Post date:** [August 27, 2020, 8:58am UTC](https://discourse.julialang.org/t/is-there-a-way-to-distribute-an-array-to-different-argument-positions-in-a-function/45616/1 "2020-08-27T08:58:01Z")

</div>

Specifically I am seeking something like the following in python:

```julia
def foo(x,y):
    return x+y
a = [1,2]
foo(*a)

```

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [August 27, 2020, 9:02am UTC](https://discourse.julialang.org/t/is-there-a-way-to-distribute-an-array-to-different-argument-positions-in-a-function/45616/2 "2020-08-27T09:02:16Z")

</div>

```julia
julia> function foo(x,y)
       x+y
       end
foo (generic function with 1 method)

julia> a=[1,2]
2-element Array{Int64,1}:
 1
 2

julia> foo(a...)
3

```

It’s called splatting:  
[https://docs.julialang.org/en/v1/manual/faq/#The-two-uses-of-the-…-operator:-slurping-and-splatting](https://docs.julialang.org/en/v1/manual/faq/#The-two-uses-of-the-...-operator:-slurping-and-splatting)

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [August 27, 2020, 11:18am UTC](https://discourse.julialang.org/t/is-there-a-way-to-distribute-an-array-to-different-argument-positions-in-a-function/45616/3 "2020-08-27T11:18:22Z")

</div>

Note that you want to be careful with splatting large arrays, because contrary to Python, Julia usually specializes on positional and keyword arguments, so if the array you are splatting is large, compile time latency can get out of hand quite quickly. Splatting typically works best for relatively small tuples, because tuples are always statically sized and always contain all the type information the Julia compiler needs to generate efficient code. In these cases, splatting is often free at runtime, which can be really useful.
