Julia Language Conditionals Ternary conditional operator


Example

pushunique!(A, x) = x in A ? A : push!(A, x)

The ternary conditional operator is a less wordy if...else expression.

The syntax specifically is:

[condition] ? [execute if true] : [execute if false]

In this example, we add x to the collection A only if x is not already in A. Otherwise, we just leave A unchanged.

Ternary operator References: