Promoting a broadcasted array

One way:

julia> _ifelse(cond::Bool, x, y) = ifelse(cond, promote(x, y)...)

julia> _ifelse.([true, false], [1,2], [3.0,4.5])
2-element Vector{Float64}:
 1.0
 4.5

I don’t know why ifelse doesn’t work this way by default – when is it a good idea to avoid the branch of cond ? x : y while preserving a type instability?

2 Likes