toResultEager method

FutureResult<List<S>, F> toResultEager()

Transforms an Iterable of FutureResults into a single result where the ok value is the list of all successes. If any error is encountered, the first error is used as the error result. The order of S and F is determined by the order in which futures complete.

Implementation

FutureResult<List<S>, F> toResultEager() async {
  List<S> list = [];
  Result<List<S>, F> finalResult = Ok(list);
  await for (final result in _streamFuturesInOrderOfCompletion(this)) {
    if (result.isErr()) {
      return Err(result.unwrapErr());
    }
    list.add(result.unwrap());
  }
  return finalResult;
}