asyncSingle<T> function

Future<T> asyncSingle<T>(
  1. List<T> items,
  2. Future<bool> filter(
    1. T item
    )
)

Returns a future that completes with the unique 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 all the other filter futures complete with false. If all filter futures complete with false or (at least 2 complete with true and all the ones before them complete), then it completes with an error.

Example: prisonersDilemmaWinner = asyncSingle(prisoners, defects);

Implementation

Future<T> asyncSingle<T>(List<T> items, Future<bool> filter(T item)) =>
    asyncWhere<T>(items, filter).single;