Varargs function

Hi,

I have a function that takes a variable number of arguments like the following:

function view(vargs...)
  out = DataFrame(vargs)
  out
end

I want the ouput of view to be the same as if I was using DataFrame, example:

DataFrame(Symbol("Period") => ["T", "T-1"], Symbol("Type") => [1, 2])

same as

view(Symbol("Period") => ["T", "T-1"], Symbol("Type") => [1, 2])

I am missing an operation inside view to “un-vectorise” the inputs. Would you please be able to help?

Thank you

I think you want splat:

view(args...) = DataFrame(args...)

Note that f([1,2,3]...) === f(1,2,3).

2 Likes

You’re looking for ... :slight_smile:

function view(vargs...)
  out = DataFrame(vargs...)
  out
end

... in a function definition “slurps” up multiple arguments, whereas it “splats” them when used in a call.

2 Likes

Ha, beat you to it!

1 Like

Thank you guys.