# Calling a function with variable numbers of parameters using an array

**URL:** <https://discourse.julialang.org/t/calling-a-function-with-variable-numbers-of-parameters-using-an-array/43235>\
**Category:** General Usage\
**Created:** [July 17, 2020, 12:49pm UTC](https://discourse.julialang.org/t/calling-a-function-with-variable-numbers-of-parameters-using-an-array/43235 "2020-07-17T12:49:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![grahamstark](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grahamstark/32/5200_2.png) [@grahamstark](https://discourse.julialang.org/u/grahamstark)\
**Post date:** [July 17, 2020, 12:49pm UTC](https://discourse.julialang.org/t/calling-a-function-with-variable-numbers-of-parameters-using-an-array/43235/1 "2020-07-17T12:49:21Z")

</div>

There is a function I want to call that accepts a variable number of parameters of a given type. If I have an array of objects of that type (or some other collection), is there some trick I can use to just pass the collection to the function, instead of manually unpacking it?

Specifically, the function is [this one](https://github.com/jmboehm/RegressionTables.jl/blob/master/src/regtable.jl), which pretty-prints multiple regression results, and I have a collection of regressions generated in a loop that I’d like to feed to it.

thanks,

Graham

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [July 17, 2020, 1:12pm UTC](https://discourse.julialang.org/t/calling-a-function-with-variable-numbers-of-parameters-using-an-array/43235/2 "2020-07-17T13:12:55Z")

</div>

Yes there is! “Spatting” with `...`

```julia
# define
f(x...) = sum(x)

x = ones(4)
# splat a collection
f(x...) # 4

```

---

<div class="post-metadata">

**Author:** ![grahamstark](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grahamstark/32/5200_2.png) [@grahamstark](https://discourse.julialang.org/u/grahamstark)\
**Post date:** [July 17, 2020, 1:40pm UTC](https://discourse.julialang.org/t/calling-a-function-with-variable-numbers-of-parameters-using-an-array/43235/3 "2020-07-17T13:40:25Z")

</div>

Oh, excellent, thanks.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 17, 2020, 1:53pm UTC](https://discourse.julialang.org/t/calling-a-function-with-variable-numbers-of-parameters-using-an-array/43235/4 "2020-07-17T13:53:10Z")

</div>

You might want to consider making the function work on a single element and broadcasting over a vector instead, but it depends a little on your application.
