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) {
    switch (e) {
      case Ok(value: final v):
        buffer.add(v);
      case Err():
        return const None();
    }
  }
  return Some(buffer);
}