-
Notifications
You must be signed in to change notification settings - Fork 207
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
Logical compound assignment operators &&= and ||= #23
Comments
The following prints out void main() {
var a = false;
a |= true;
print(a);
} So maybe it's already implemented? |
No, that's a slightly different thing: The statement This matters in practice, because you can use |
Ah, I see. |
Hey there, was this abandoned? If I have this: onPressed: doSomething, I'd like to be able to do: onPressed: doSomething && doSomethingElse || doSomethingElseEntirely, By defining something like: extension FunctionExtension on bool Function(String) {
bool Function(String) operator &&=(bool Function(String) other) =>
(String value) => this(value) || other(value);
bool Function(String) ||=(bool Function(String) other) =>
(String value) => this(value) && other(value);
} |
It is not abandoned, cf. #1077. However, you cannot declare an instance operator for any compound assignment ( typedef F = bool Function(String);
extension LiftBool on F {
F operator &(F other) => (s) => this(s) && other(s);
F operator |(F other) => (s) => this(s) || other(s);
}
bool succeed(String s) { print('Succeed: $s'); return true; }
bool fail(String s) { print('Fail: $s'); return false; }
bool notReached(String s) => throw 'Not reached';
void main() {
(succeed & succeed | notReached)('Hello');
(fail & notReached | succeed)('world!');
} |
Cf. issues dart-lang/sdk#26996, meta, and dart-lang/sdk#26997, analyzer, (there are others, but they should probably be replaced by a single front-end issue), the compound assignment operators
&&=
and||=
have been in the pipeline for a full specification and an implementation for a long time.We ought to find a placement for this task in terms of milestones and priorities, or drop it.
The text was updated successfully, but these errors were encountered: