# Assign name to operator with ternary operator

**URL:** <https://discourse.julialang.org/t/assign-name-to-operator-with-ternary-operator/72518>\
**Category:** General Usage\
**Created:** [December 3, 2021, 12:39pm UTC](https://discourse.julialang.org/t/assign-name-to-operator-with-ternary-operator/72518 "2021-12-03T12:39:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbrnr](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@cbrnr](https://discourse.julialang.org/u/cbrnr)\
**Post date:** [December 3, 2021, 12:39pm UTC](https://discourse.julialang.org/t/assign-name-to-operator-with-ternary-operator/72518/1 "2021-12-03T12:39:17Z")

</div>

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:

```julia
if true
    f = >=
else
    f = <
end

```

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:

```julia
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?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 3, 2021, 12:40pm UTC](https://discourse.julialang.org/t/assign-name-to-operator-with-ternary-operator/72518/2 "2021-12-03T12:40:59Z")

</div>

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

```

seems to work

---

<div class="post-metadata">

**Author:** ![cbrnr](https://avatars.discourse-cdn.com/v4/letter/c/919ad9/32.png) [@cbrnr](https://discourse.julialang.org/u/cbrnr)\
**Post date:** [December 3, 2021, 12:44pm UTC](https://discourse.julialang.org/t/assign-name-to-operator-with-ternary-operator/72518/3 "2021-12-03T12:44:47Z")

</div>

> [@lmiq](#):
>
> `f = true ? (>=) : (<)`

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

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 3, 2021, 12:45pm UTC](https://discourse.julialang.org/t/assign-name-to-operator-with-ternary-operator/72518/4 "2021-12-03T12:45:44Z")

</div>

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