tryReduce method
Result<T?, E>
tryReduce(
- T f(
- T,
- T
Reduces the elements to a single one by repeatedly applying a reducing operation. If a Err is encountered it is returned.
Implementation
Result<T?, E> tryReduce(T Function(T, T) f) {
if (!moveNext()) {
return Ok(null);
}
var accumRes = current;
if (accumRes.isErr()) {
return accumRes.intoUnchecked();
}
var accum = accumRes.unwrap();
while (moveNext()) {
if (current.isErr()) {
return current.intoUnchecked();
}
accum = f(accum, current.unwrap());
}
return Ok(accum);
}