flattenAll<T> method

Result<List<T>> flattenAll <T>(Iterable<Result<T>> results)

Converts a sequence of results to a result of a list.

Returns either a list of values if results doesn't contain any errors, or the first error result in results.

Implementation

static Result<List<T>> flattenAll<T>(Iterable<Result<T>> results) {
  var values = <T>[];
  for (var result in results) {
    if (result.isValue) {
      values.add(result.asValue.value);
    } else {
      return result.asError;
    }
  }
  return new Result<List<T>>.value(values);
}