Pattern destructuring could enable calling FunctionType
s #4234
Open
Description
Today we have patterns that allow us to deconstruct a variable:
class Class {
int myField = 0;
}
void foo() {
var instance = Class();
if (instance case Class(myField: var myFieldValue)) {}
}
I think of this structure like:
// getter assigns to variable
Class(myField: var myFieldValue)
Basically the =
operator but swapped:
var myFieldValue = instance.myField;
We also can get a method as a FunctionType
:
class Class {
int foo() => 0;
}
void foo() {
var instance = Class();
if (instance case Class(foo: var fooFn)) {
fooFn(3);
}
}
I'd like to request a change in that we could:
if (instance case Class(foo(3): var fooValue)) {
And for Future
we could add await
before var
like:
class Class {
Future<int> foo() async => 0;
}
void foo() async {
var instance = Class();
if (instance case Class(foo(3): await var fooValue)) {
print(fooValue);
}
}