Consider implementing a "true" ternary operator #179
Replies: 2 comments 2 replies
-
Although I think adding true-ternary syntax (or even more general if/else/switch/case/etc.) is worthwhile, it is actually possible to achieve the functionality right now with an array-wrapping trick.
|
Beta Was this translation helpful? Give feedback.
-
Ternary Operator ExpressionThis is a work-in-progress draft for an upcoming proposal to introduce a ternary operator (or expression) to the language. Please, use this discussion page to discuss the merits and other finer points about this draft. AbstractMotivationFrom Gitter’s @hell_racer comment "I've used similar 'object-wrapping' trick before :), but I wasn't aware of this one. Thanks! That said, I think it might be a bit difficult for junior developers to grasp, so having the ternary operator would still be a nice addition." (emphasis, mine). Grammar ChangesThe following updates to the grammar support a ternary operation: expression =/ ternary-expression
ternary-expression = expression "?" expression ":" expression // TODO discuss precedence Compliance TestsAlternatives// TODO: this page discussioncomment-11824335 |
Beta Was this translation helpful? Give feedback.
-
Most languages do have a ternary operator that is akin to an if-then-else syntax as a single statement.
For instance, many languages do have the following syntax:
Unfortunately JMESPath does not have a ternary operator.
The closest approximation suffers from a limitation that makes it not really a true ternary operator.
Please, consider introducing ternary operator to the language.
Beta Was this translation helpful? Give feedback.
All reactions