Tuple destructuring / zip() on tuple of arrays

Hi!

Is it possible to make zip() work on a Tuple of Arrays or to expand/destructure a Tuple?

I have a function returning a Dictionary but I would like it to instead return 2 arrays (keys & values) in case I don’t want a Dictionary:

function myfunc(...) 
...
   return array_1, array_2
end

And I would like something like this to work:

my_dict = Dict(zip(myfunc(...)))

or:

my_dict = Dict(zip(expand(myfunc(...))))

Is there something like expand()? I couldn’t find it in the Docs.
Thanks!

You can say Dict(zip(myfunc(x, y, z)...)) or Dict(Pair.(myfunc(x, y, z))).

The ... here is the splat operator which will call zip with the individual elements of the tuple (array_1, array_2) returned from myfunc.

1 Like

It works! Thanks for the speedy response!

1 Like