OLD | NEW |
| (Empty) |
1 | |
2 library which.src.util; | |
3 | |
4 import 'dart:async'; | |
5 | |
6 /// Transparently call `firstWhere` on a [Stream] or [Iterable]. | |
7 // TODO: Remove once https://dartbug.com/ is fixed. | |
8 firstWhere(sequence, test, { orElse() }) => sequence is Iterable ? | |
9 sequence.firstWhere(test, orElse: orElse) : | |
10 _streamFirstWhere(sequence, test, orElse: orElse); | |
11 | |
12 Future _streamFirstWhere(Stream stream, test(item), { orElse() }) { | |
13 var pairs = stream.asyncMap((item) => test(item).then((result) => [item, resul
t])); | |
14 return pairs.firstWhere((pair) => pair.last, defaultValue: () => [orElse(), nu
ll]).then((pair) => pair.first); | |
15 } | |
16 | |
17 /// The identity function simply returns its argument ([x]). | |
18 identity(x) => x; | |
OLD | NEW |