Elvis operator in expressions: `?.`
See original GitHub issueCurrently a.b.c
will thrown an error in expression if a
is null
. To suppress null dereferencing we should support a?.b.c
which would short circuit further evaluation if a
is null. In this way we could have explicit notation which would show which values could be null
.
Syntax to fallow dart proposal: https://github.com/gbracha/nullAwareOperators/blob/master/README.md
Issue Analytics
- State:
- Created 9 years ago
- Reactions:2
- Comments:45 (33 by maintainers)
Top Results From Across the Web
Elvis operator - Wikipedia
In certain computer programming languages, the Elvis operator, often written ?: , is a binary operator that returns its first operand if that...
Read more >Expressions And Operators: Ternary
The ternary operator ? : is a shorthand for if statements. It is an expression, so it evaluates to a value. For example:...
Read more >Spring SpEL - Elvis Operator - Tutorialspoint
SpEL expression supports Elvis operator which is a short form of ternary operator. // Using ternary operator String result = name != null...
Read more >Kotlin Elvis Operator - Javatpoint
Elvis operator (?:) is used to return the not null value even the conditional expression is null. It is also used to check...
Read more >What does ?: do in Kotlin? (Elvis Operator) - Stack Overflow
In certain computer programming languages, the Elvis operator ?: is a binary operator that returns its first operand if that operand is true...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Feels kind of weird to me; it’s surprising to have language extensions within the binding expression syntax.
This might also need some more thinking, but I don’t see this as being that useful. If angular defaults to gracefully handling null dereferencing in expression then the developer doesn’t have to care whether something is loaded lazy or not. The times when people do care is when something needs to be shown in place of the pending data, which will still be handled with an
if
@vicb @mhevery Sorry for resurrecting this but I want to point out that the safe-navigation-operator and the “Elvis” operator are two different things. See Wikipedia , Groovy-Elvis, Groovy-Safe-Navigation. The Elvis operator is more akin to the Null coalescing operator with the difference that it tests for “truthy” instead of null for the lhs.
I think it is bad practice to take established terminology from other languages and change its meaning. What angular currently has is a safe-navigation-operator and not the Elvis operator. Calling it
Angular “Elvis” operator ( ?. )
does not make it better 😉