Skip to content

if - assignment operator #820

Open
Open
@vsevolod19860507

Description

@vsevolod19860507

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions