sequenceList method

Option<List<T>> sequenceList()

Turns an Iterable<Result<T>> into an Option<List<T>>. If all elements are Ok, it returns a Some<List<T>>. If any element is an Err, it returns None, discarding the specific error.

Implementation

Option<List<T>> sequenceList() {
  final buffer = <T>[];
  for (final e in this) {
    if (e.isErr()) {
      return const None();
    }
    buffer.add(e.unwrap());
  }
  return Some(buffer);
}