I was about to refer a colleague the docs on the non-array form of comprehensions (with multiple for
, optionally if
), but I can’t find it. Eg in
julia> [(i = i, j = j) for i in 1:2, j in 1:3]
2×3 Array{NamedTuple{(:i, :j),Tuple{Int64,Int64}},2}:
(i = 1, j = 1) (i = 1, j = 2) (i = 1, j = 3)
(i = 2, j = 1) (i = 2, j = 2) (i = 2, j = 3)
julia> [(i = i, j = j) for i in 1:2 for j in 1:3]
6-element Array{NamedTuple{(:i, :j),Tuple{Int64,Int64}},1}:
(i = 1, j = 1)
(i = 1, j = 2)
(i = 1, j = 3)
(i = 2, j = 1)
(i = 2, j = 2)
(i = 2, j = 3)
julia> [(i = i, j = j) for i in 1:2 for j in 1:3 if j ≤ i]
3-element Array{NamedTuple{(:i, :j),Tuple{Int64,Int64}},1}:
(i = 1, j = 1)
(i = 2, j = 1)
(i = 2, j = 2)
the first one is documented in the Multi-dimensional Arrays section, but what about the second and the third?