or method

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

Returns this result if it's a success, otherwise other.

Use this to provide a fallback result when the first result fails. The first successful result is returned; if both fail, the second error is returned. Useful for fallback operations like cache-then-network. For computed fallbacks based on the error, use orElse instead.

Example:

Result<int, String> a = Err('failed', StackTrace.current);
Result<int, String> b = Ok(10);
final result = a | b; // Returns b (Ok(10))
final cached = getCachedResult() | fetchFresh(); // Try cache first

Implementation

Result<T, E> or(Result<T, E> other) {
  if (this is Ok<T, E>) return this;

  return other;
}