Fused ternary operator?


#1

Am I right there’s no “easy” way to broadcast the ternary operator? E.g.

x = [0,1,2]
@. x==0 ? 0. : 1/x   #this doesn't work

Of course, its easy enough to write the code yourself,

broadcast(x->(x==0 ? 0. : 1/x), [0,1,2])

But is there any way to do this more nicely already? Or is this a feature people would want?


#2

What about broadcasting ifelse?


#3

Ah did not know about that built-in, that’s basically exactly the nicer way to do it. Thanks!