This is my desired behavior...
result = []
for element in iterable
if(condition)
push!(result, element)
else
continue
end
end
But when using an array comprehension in Julia with a ternary operator, I'm not sure what the analogous "continue" would be aside from using nothing. Which results in undesired Vector{Union{Nothing, ...}}.
result = [(condition ? element : nothing) for element in iterable]
For example:
vec1 = []
for v in -1:1
if(v==0)
push!(vec1,v)
else
continue
end
end
returns
julia> vec1
1-element Vector{Any}:
0
Meanwhile
vec2 = [(v==0 ? v : nothing) for v in -1:1]
returns
julia> vec2 = [(v==0 ? v : nothing) for v in -1:1]
3-element Vector{Union{Nothing, Int64}}:
nothing
0
nothing
instead of just a normal Vector{Int64}