Julia Language Conditional Array Comprehension


Example

Before the Julia 0.5, there is no way to use conditions inside the array comprehensions. But, it is no longer true. In Julia 0.5 we can use the conditions inside conditions like the following:

julia> [x^2 for x in 0:9 if x > 5] 
4-element Array{Int64,1}:
 36
 49
 64
 81

Source of the above example can be found here.

If we would like to use nested list comprehension:

julia>[(x,y) for x=1:5 , y=3:6 if y>4 && x>3 ]
4-element Array{Tuple{Int64,Int64},1}:
 (4,5)
 (5,5)
 (4,6)
 (5,6)