I’d like to write a vararg function which takes N vectors, and return all possible length-N vectors by picking one element from each vector. For example
Check out the built-in Iterators.product function:
help?> Iterators.product
product(iters...)
Return an iterator over the product of several iterators. Each generated element is a tuple whose ith element comes from the ith argument iterator. The first iterator changes the fastest.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> collect(Iterators.product(1:2, 3:5))
2×3 Array{Tuple{Int64,Int64},2}:
(1, 3) (1, 4) (1, 5)
(2, 3) (2, 4) (2, 5)
Note that product expects each iterator to be a separate argument, so you can take the product of an array of iterators by doing product(my_vector_of_vectors...) using ... to splat the collection into multiple arguments.
Also, you may get better performance by storing a tuple of vectors instead of a vector of vectors, since your individual inner vectors have different types. That would look like: