Skip to content
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

Elvis operator or similar #1715

Closed
Wdestroier opened this issue Jun 29, 2021 · 2 comments
Closed

Elvis operator or similar #1715

Wdestroier opened this issue Jun 29, 2021 · 2 comments
Labels
feature Proposed language feature that solves one or more problems

Comments

@Wdestroier
Copy link

Hi! Sometimes in Flutter I have to pass a widget only if a variable is not null.

Example:

return personImage == null ? null : Avatar(image: personImage);

I would like to suggest a language feature for this.
A syntax sugar that exists in other languages is the elvis operator:

return personImage ?: Avatar(image: personImage);

Maybe we can have the elvil operator:

return x 3:) y;

Or the happy operator:

return x :) y;

Or the inverse if null operator:

return x ¿¿ y;

Just kidding!
I wonder what could be a great looking syntax...

@Wdestroier Wdestroier added the feature Proposed language feature that solves one or more problems label Jun 29, 2021
@Levi-Lesches
Copy link

return x ¿¿ y;

Well, I'd hate to have to type that out!

Here's another issue with exactly the same request (x !! y): #361. How about closing this and subscribing there?

@Wdestroier
Copy link
Author

Ok, sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

2 participants