Assign name to operator with ternary operator

I want to use different comparisons (either >= or <) based on some condition. I thought I’d just define a name f pointing to the corresponding operation, which works with the following code:

if true
    f = >=
    f = <

I can then compare using f(x, y).

However, I can’t figure out how to shorten this if/else condition with the ternary operator. The following code does not work:

f = true ? >= : <

This gives an error syntax: ">=" is not a unary operator, which doesn’t really help me. Is it not possible to do that?

f = true ? (>=) : (<)

seems to work


Thanks! Now I feel dumb because this seems really obvious.

I don’t think it is obvious, that is of course some corner case of parsing syntax.

1 Like