or<F> method

Result<T, F> or<F>(
  1. Result<T, F> other
)

Returns this result when it succeeded, or other otherwise.

other is evaluated before the call. Use orElse when the fallback needs the error or is expensive to build.

final value = const Err<int, String>('cache miss')
    .or(const Ok<int, String>(42)); // Ok(42)

Implementation

Result<T, F> or<F>(Result<T, F> other) {
  return switch (this) {
    Ok<T, E>(:final value) => Ok<T, F>(value),
    Err<T, E>() => other,
  };
}