tryReduce<E extends Object> method

Result<Option<T>, E> tryReduce<E extends Object>(
  1. Result<T, E> f(
    1. T,
    2. 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<Option<T>, E> tryReduce<E extends Object>(
    Result<T, E> Function(T, T) f) {
  if (!moveNext()) {
    return Ok(None);
  }
  var accum = current;
  while (moveNext()) {
    final next = current;
    final res = f(accum, next);
    if (res.isErr()) {
      return res.intoUnchecked();
    }
    accum = res.unwrap();
  }
  return Ok(Some(accum));
}