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