Lasse R.H. Nielsen
Lasse R.H. Nielsen
One way would be ```dart List list = ...; X? firstOrNull = list.cast.firstWhere((v) => test(v!), orElse: () => null); ``` In practice, I'd go for an extension method.
It's not impossible. I was targeting them for `package:collection` (https://github.com/dart-lang/collection/pull/135), and I'm a little disinclined to add extension methods for something that really should be real methods in the library...
If you are null safe, then you can use `package:collection`'s new [`firstWhereOrNull`](https://pub.dev/documentation/collection/1.15.0/collection/IterableExtension/firstWhereOrNull.html) ([FAQ](https://dart.dev/null-safety/faq#the-iterablefirstwhere-method-no-longer-accepts-orelse---null)).
There is no similar method in `package:async` (yet), so you'll have to make do with: ```dart extension on Stream { Future get firstWhereOrNull async { await for (var e in...
Casting `null as String` will throw in sound null-safe mode, so it's not a long-term strategy.
An `await controller.close()` won't complete until the event is delivered. It won't be delivered until someone listens to the stream. In this test, nobody listens to the stream, so "asynchronously...
I also looked at which zones were in play. An instrumented version of the original example, where it gives numbers to zones and shows the current zone and its parent...
> It can take a lot of time to find exactly which line was responsible for generating a specific code. How would one define which line was responsible for a...
> only uses `_test.dart` to know if a file is a test That's also fragile. If you have a test split into multiple libraries, perhaps some code is shared between...
A quick look at your test file makes me think that "wrap 2" is unnecessary, and "wrap 3" is necessary because the test framework just doesn't understand zones. (It uses...