Suppose I only want to know success but not failure in a statement like:
julia> [i%2==1 && "even" for i in 1:10]
10-element Vector{Any}:
"even"
false
"even"
false
"even"
false
"even"
false
"even"
false
To stop this loop from outputting false
, I tried the following but it doesn’t work:
julia> [i%2==1 ? "even" : nothing for i in 1:10]
10-element Vector{Union{Nothing, String}}:
"even"
nothing
"even"
nothing
"even"
nothing
"even"
nothing
"even"
nothing
How can I get this one-liner to just give:
5-element Vector{Union{Nothing, String}}:
"even"
"even"
"even"
"even"
"even"