-
Notifications
You must be signed in to change notification settings - Fork 204
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 |
Admin comment: this is being implemented, feature specification, implementation issue.
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: