toResult method
Transforms an Iterable of FutureResults into a single result where the ok value is the list of all successes
and err value is a list of all failures. The order of S
and F
is determined by
the order in the List.
Implementation
FutureResult<List<S>, List<F>> toResult() async {
List<S> okList = [];
late List<F> errList;
Result<List<S>, List<F>> finalResult = Ok(okList);
for (final result in this) {
final resultSync = await result;
if (finalResult.isOk()) {
if (resultSync.isOk()) {
okList.add(resultSync.unwrap());
} else {
errList = [resultSync.unwrapErr()];
finalResult = Err(errList);
}
} else if (resultSync.isErr()) {
errList.add(resultSync.unwrapErr());
}
}
return finalResult;
}