tryFold<U> method

Result<U, E> tryFold<U>(
  1. U initial,
  2. U f(
    1. U,
    2. T
    )
)

An iterator method that applies a function producing a single value, returns Err is encounted.

Implementation

Result<U, E> tryFold<U>(U initial, U Function(U, T) f) {
  var accum = initial;
  for (final res in this) {
    if (res.isErr()) {
      return res.intoUnchecked();
    }
    accum = f(accum, res.unwrap());
  }
  return Ok(accum);
}