6 ms·
After some thinking, the ternary conditional operator can be decomposed into 2 composing binary operators like such: ? takes a bool, a T, and returns option<T>
by pistoleer 2y ago
After some thinking, the ternary conditional operator can be decomposed into 2 composing binary operators like such:
? takes a bool, a T, and returns option<T>
true?b == Result b
false?b == None
: takes an Option<T> and a T and returns T
Result x : y == x
None : y == y
However, in most languages (looking at you php) the ?: act as a type of parenthesis: in a?b:c, any expression goes into b, no matter it's precedence.