-
Notifications
You must be signed in to change notification settings - Fork 209
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
Wildcard variables #3712
Comments
I always love seeing those usage-pattern breakdowns across huge corpuses of Dart code! From the proposal:
As one of those users I just wanted to add that my two use cases for doing this are to workaround #8 (unless there's a better issue to reference?) xs.map((_) => _.isEven);
// vs
xs.map(.isEven); // strawman syntax and #3001: users.map((_) {
final (user, selected) = _;
...
})
// vs
users.map((user, selected) {
...
}) |
I've tried to hunt down the places in the specification that would need to change to make wildcard variables work. Collected here: https://gist.github.com/lrhn/c14c76c665a1e20f42e283d1fe6e6e02 Those changes (plus the similar places I've missed) should simply make (If we get #3807, more changes are needed, to not make it an error for an optional parameter named |
Yeah, it's not an unreasonable use of |
I have no issue considering Short names are allowed for iteration variables. Nobody complains about |
We should probably update https://dart.dev/effective-dart/style#prefer-using-_-__-etc-for-unused-callback-parameters as part of this feature? cc @munificent Added dart-lang/site-www#6446 to track |
BTW, shouldn't this issue be closed? |
We probably should. @kallentu are you aware of any further wrap-up work, or can we consider it done? |
Note, issue on definition of Also we had this problem related to wildcard variables and if you've not close to main on your SDK, this might still be happening for you (the CP has landed already): |
There is some follow up work needed for the feature:
I'm working on them at the moment, so they will be completed soon. |
Finished the work for the two issues I've linked above. Let's close out this issue 🚀 If any other bugs arise, I'll keep track of those, but in general -- we're good to go here. |
Admin comment: this is being implemented, feature specification, implementation issue, experiment flag
wildcard-variables
.Pattern matching brought a new way to declare variables. Inside patterns, any variable whose name is
_
is considered a "wildcard". It behaves like a variable syntactically, but doesn't actually create a variable with that name. That means you can use_
multiple times in a pattern without a name collision.That leads to an irregularity:
Also, it's annoying that
_
binds a name. When you have a lambda with more than one parameter that you don't use, you end up having to do:takesCallback((_, __, ___) { ... });
I have a proposal to fix both by saying that local variables and parameters named
_
are also non-binding. This is the tracking issue for that proposal.The text was updated successfully, but these errors were encountered: