Skip to content

Null-aware collection-for #3730

Open
Open
@anqit

Description

@anqit

Currently, for collection-for's on nullable collections, we need a null check:

List<int>? myInts = ...;

if (myInts != null) {
    for (final i in myInts) {
        // use i
    }
}

It would be nice if we could have a null-aware version of this syntax, something along the lines of

for(final i in myInts?) ...

or

for(final i in? myInts) ...

which would skip iteration if the iterable were null.

Sorry if this already exists and I'm just (null-)unaware of it :)

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