tryReduce method
Reduces the elements to a single one by repeatedly applying a reducing operation. If a Err is encounted it is returned.
Implementation
Result<Option<T>, E> tryReduce(T Function(T, T) f) {
if (!moveNext()) {
return Ok(None);
}
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(Some(accum));
}