Skip to content

More null-aware operatorsΒ #27716

Open
Open
@mehmetf

Description

@mehmetf

It would be nice to have a shorthand for this:

val == null ? null : method(val);

This is the opposite of val ?? method(val) which only returns method(val) when val is null.

We love the null friendly operators so it bugs me a lot that I can't do this. Normally you would not need it if method can do ?. everywhere but sometimes the shorthand helps. For instance, some operators are not null friendly:

double convertFromMicro(Int64 value) =>
    value == null ? null : value.toDouble() / _microDollars;

value?.toDouble() / _microDollars would blow up if value is null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).core-mtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions