Add let conditions
See original GitHub issueOccasionally, it can be useful to introduce a new variable in a condition list.
if (is BaseMemberExpression bme = that.primary,
let text = identifierText(bme.identifier),
(importMemberAliases[text] else text) in inlineAnnotations) {
// ...
}
It would be nice if that was legal syntax, instead of having to use workarounds like this:
if (is BaseMemberExpression bme = that.primary,
exists text = identifierText(bme.identifier) of String?,
(importMemberAliases[text] else text) in inlineAnnotations) {
// ...
}
However, there is one problem: let
conditions as shown above are very different from let
statements, expressions, and (once implemented: see #3483) comprehension clauses – they only introduce one variable, and they aren’t parenthesized. To introduce multiple variables, you would use multiple let
conditions instead of one let
with multiple patterns. I’m not sure how much that bothers me.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How to add two conditions using let in Android Kotlin
I will prefer without let if (it.data?.name?.isNotEmpty() == true) { // data is not null and name is not empty }.
Read more >let - JavaScript - MDN Web Docs
let allows you to declare variables that are limited to the scope of a block statement, or expression on which it is used,...
Read more >LET function - Microsoft Support
The LET function assigns names to calculation results. This allows storing intermediate calculations, values, or defining names inside a formula.
Read more >SQL: Combining the AND and OR Conditions - TechOnTheNet
This SQL tutorial explains how to use the AND condition and the OR ... to test for multiple conditions in a SELECT, INSERT,...
Read more >How to Use Variables & Conditions in Articulate Storyline
Are you intimidated by variables and conditions in Articulate Storyline? ... Variables 35:00 Add in More Conditions 37:46 Test the Project ...
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 FreeTop 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
Top GitHub Comments
It seems to me that the natural syntax for this would be:
The
let
keyword would be neither regular, nor necessary here.I guess what you are trying to achieve by
is either
I do have to say that 1. is something that personally annoys me every now and then. I wonder if there could be some construct to avoid duplicating/outsourcing the else blocks even if you have nested if statements with code in between… Kindof like throwing an exception “blah this didn’t work out, fallback behaviour please”… Hmm could it perhaps even be plausible to use the exception construct but not actually throw exception… i.e. optimize the case when it is caught locally AND exception object never used… 😃 Not that I like try blocks very much… they mess with the otherwise beautiful indentation of code 😃