Calling a function with variable numbers of parameters using an array

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, 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

Yes there is! “Spatting” with ...

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

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

Oh, excellent, thanks.

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.

1 Like