asyncFirst<T> function
Returns a future that completes with the first item in items
for which
filter
returns a future that completes with true. It completes with an
item only when its filter future completes with true AND the filter futures
for all previous items have completed.
If all filter futures complete with false and orElse
is absent, completes
with an error.
If all filter futures complete with false and orElse
is present,
completes with the return value of orElse
.
Example: newKing = asyncFirst(sons, survivesToMaturity);
Implementation
Future<T> asyncFirst<T>(List<T> items, Future<bool> filter(T item),
{T orElse()?}) =>
asyncWhere<T>(items, filter)
.firstWhere((_) => true, orElse: orElse)
.then((x) => x);