-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Object Deconstruction or Else Statements #3506
Comments
For reference, from another language: here |
This seems similar to #2703. You can see the discussion there. |
Similar, but different. This is specifically for object deconstruction and fits well into the existing syntax and does not require reserving a new keyword like "let". If "if-case" statements are one side of the coin, then "Object Deconstruction or Else" is the other side of the coin. void main(){
ABC abc = A(1);
int a;
if(abc case A(a:final innerA)){
a = innerA;
}
else {
return;
}
// use a
} Example with proposed syntax: void main(){
ABC abc = A(1);
A(:final a) = abc else {
return;
}
// use a
} |
I would like to have something like Swift's "guard let" or Rusts "let if" as well. I'm going to merge this issue with #2537, which discusses that more generally without being pinned to a specific syntax. |
Given
Dart already supports object deconstruction:
And Dart supports If-Case statements:
Therefore Dart should also support Object Deconstruction or Else Statements:
This is effectively a pattern matching guard clause.
The text was updated successfully, but these errors were encountered: