Skip to content

Let's make new Feature ?== or ??= #43664

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

Closed
Hellomik2002 opened this issue Oct 3, 2020 · 5 comments
Closed

Let's make new Feature ?== or ??= #43664

Hellomik2002 opened this issue Oct 3, 2020 · 5 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).

Comments

@Hellomik2002
Copy link

Hellomik2002 commented Oct 3, 2020

a == null ? null : something(a)

let's change to

a ?== something(a)

it is a little fun feature like this

a ?? false
@znjameswu
Copy link

FYI, ??= is an existing operator for nullable assignment.

@mit-mit
Copy link
Member

mit-mit commented Oct 5, 2020

Yes, I think you are describing the current null-aware assignment operator:
https://dart.dev/guides/language/language-tour#assignment-operators

// Assign value to a
a = value;
// Assign value to b if b is null; otherwise, b stays the same
b ??= value;

@mit-mit mit-mit added the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label Oct 5, 2020
@mit-mit mit-mit closed this as completed Oct 5, 2020
@Hellomik2002
Copy link
Author

final a = null or 'some string'
I don't want to assign value to a,
I mean
final c = a == null ? null : something(a)
use like
final c = a ?== something(a)
??= can not change value of final variable

@mit-mit
Copy link
Member

mit-mit commented Oct 5, 2020

Sorry, I don't understand. Can you specify in a bit more detail what the semantics of this proposed construct are?

@eernstg
Copy link
Member

eernstg commented Oct 5, 2020

I think the proposal is to have syntax for evaluating something(a) if a is non-null, like

((v) => v != null ? something(v) : null)(a)

and, in general, to enable "subexpression null shorting" in the sense that an expression is evaluated only if certain subexpressions are non-null.

We have had some discussions about this before (but there doesn't seem to be an issue specifically on that, so it must have been individual comments in other discussions, e.g., this one).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Projects
None yet
Development

No branches or pull requests

4 participants