Skip to content

Feature: firstOrElse variant in List #37372

Open
@Antoniossss

Description

@Antoniossss

It would be convinient to have variation of first property as method that would allow something to get first element, or produce default value insteaf of throwing wrong state exception..

Right now I am doing something like this (to avoid extra var)

var val=myList.where((i)=>i.x>5).map((i)=>i.y).firstWhere((v)=>true), orElse:()=>someDefaultValue

while I would like to terminate like this:
var val=myList.where((i)=>i.x>5).map((i)=>i.y).firstOrElse(()=>defaultValue);

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-coretype-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