dart - Adding orElse function to firstWhere method -



dart - Adding orElse function to firstWhere method -

i trying add together onelse function itterator.firstwhere method cannot syntax right.

i have tried like

class="lang-dart prettyprint-override">list<string> mylist = string result = mylist.firstwhere((o) => o.startswith('foo'), (o) => null);

but compiler has error of

1 positional arguments expected, 2 found

i sure simple syntax problem, has me stumped

'orelse' named optional argument.

class="lang-dart prettyprint-override">void main() { checkorelse(['bar', 'bla']); checkorelse(['bar', 'bla', 'foo']); } void checkorelse(list<string> values) { string result = values.firstwhere((o) => o.startswith('foo'), orelse: () => ''); if (result != '') { print('found: $result'); } else { print('nothing found'); } }

dart

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -