dart-lang / dart-lang/language

if - assignment operator

Open
#820 7 comments 7 reactions 0 assignees View on GitHub
feature
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

At the moment Dart has ternary operator that requires "else" part.
In the cases when I need something like this
```
var s1 = 3;
s1 = s1 > 3 ? 100500 : s1
```

": s1" is redunant.

Or I should use "if"

```
var s1 = 3;
if(s1 > 3){
s1 = 100500;
}
```

I think It will be useful to have another one aproach to do this, something like this:

```
var s1 = 3;
s1 ?= s1 > 3 : 100500;
```

```
var s2 = 3;
s2 ?= s2 > 3 : 100500 + 56 * 78;
```

If the condition is false than all expression ignors. And the old value will not change.

This is something like collection "if" but witout collection.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.