tryReduce<E extends Object> method
Result<T?, E>
tryReduce<E extends Object>(
- Result<
T, E> f(- T,
- T
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately.
Implementation
Result<T?, E> tryReduce<E extends Object>(Result<T, E> Function(T, T) f) {
if (!moveNext()) {
return Ok(null);
}
var accum = current;
while (moveNext()) {
final next = current;
final res = f(accum, next);
if (res.isErr()) {
return res.intoUnchecked();
}
accum = res.unwrap();
}
return Ok(accum);
}