You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
It is unlikely that we'll change the List or Iterable APIs at the current time, there are far too many implementations that would then be broken.
This functionality seems like something that can easily be implemented using extension methods, though, and anyone can add that extension.
For now, you can do:
boolkTrue(_) =>true;
var val = myList.where((i) =>i.x >5).map((i) => i.y).firstWhere(kTrue, orElse: () => defaultValue) ;
I have no problem in extending API by myown for own purpose. Actually that is more than fine for me. Can you double check your link for extension methods? It seems to be dead .
Activity
lrhn commentedon Jun 26, 2019
It is unlikely that we'll change the
ListorIterableAPIs at the current time, there are far too many implementations that would then be broken.This functionality seems like something that can easily be implemented using extension methods, though, and anyone can add that extension.
For now, you can do:
Antoniossss commentedon Jun 26, 2019
I have no problem in extending API by myown for own purpose. Actually that is more than fine for me. Can you double check your link for extension methods? It seems to be dead .
lrhn commentedon Jun 27, 2019
Link fixed.