I’m not sure I fully understand your doubt, but the script, which is certainly not as efficient as the other proposals, should work for a generic number of input vectors.
julia> as = [1,2]
2-element Vector{Int64}:
1
2
julia> bs = (3,4, 5)
(3, 4, 5)
julia> cs = [6]
1-element Vector{Int64}:
6
julia> ds = [7, 8, 9]
3-element Vector{Int64}:
7
8
9
julia> ads=[as,bs,cs,ds]
4-element Vector{Any}:
[1, 2]
(3, 4, 5)
[6]
[7, 8, 9]
julia> reduce(hmprod, ads)
18-element Vector{Any}:
(1, 3, 6, 7)
(1, 3, 6, 8)
(1, 3, 6, 9)
(1, 4, 6, 7)
(1, 4, 6, 8)
(1, 4, 6, 9)
(1, 5, 6, 7)
(1, 5, 6, 8)
(1, 5, 6, 9)
(2, 3, 6, 7)
(2, 3, 6, 8)
(2, 3, 6, 9)
(2, 4, 6, 7)
(2, 4, 6, 8)
(2, 4, 6, 9)
(2, 5, 6, 7)
(2, 5, 6, 8)
(2, 5, 6, 9)
julia> function hmprod(v...)
p=[]
i=1
for a in v[1], b in v[2]
push!(p, (a...,b))
i+=1
end
p
end
hmprod (generic function with 1 method)
I add a recursive version, which does not use functions of either Base or other packages.
julia> function rhmprod(v...)
p=Tuple[]
i=1
if length(v)>=2
for a in v[1], b in v[2]
push!(p, (a...,b))
i+=1
end
rhmprod(p,v[3:end]...)
else
v[1]
end
end
rhmprod (generic function with 1 method)
julia> rhmprod(ads...)
18-element Vector{Tuple}:
(1, 3, 6, 7)
(1, 3, 6, 8)
(1, 3, 6, 9)
(1, 4, 6, 7)
(1, 4, 6, 8)
(1, 4, 6, 9)
(1, 5, 6, 7)
(1, 5, 6, 8)
(1, 5, 6, 9)
(2, 3, 6, 7)
(2, 3, 6, 8)
(2, 3, 6, 9)
(2, 4, 6, 7)
(2, 4, 6, 8)
(2, 4, 6, 9)
(2, 5, 6, 7)
(2, 5, 6, 8)
(2, 5, 6, 9)