sieve method
Converts an Iterable<Result<T, E>>
to a <Iterable<T>
.
All Err
values are skipped.
Basic usage
final list = <Result<int, String>>[
Ok(4),
Ok(7),
Ok(2),
Err('first'),
Ok(9),
Err('second'),
];
final valueList = list.sieve();
expect(valueList, [4, 7, 2, 9]);
final list = <Result<int, String>>[Ok(1), Ok(2), Ok(3), Ok(4)];
final valueList = list.sieve();
expect(valueList, [1, 2, 3, 4]);
final list = <Result<int, String>>[
Err('Bad'),
Err('Really bad'),
Err('Really really bad'),
];
final valueList = list.sieve();
expect(valueList, <int>[]);
Implementation
Iterable<T> sieve() {
return where((Result<T, E> result) => result.isOk)
.map((Result<T, E> result) => result.unwrap());
}