and method
Chains operations: returns this result if it's an error, otherwise other.
This is useful for performing sequential operations where the second
depends on the first succeeding. If this result is Err, it's returned
unchanged (short-circuit). If this is Ok, the other result is returned.
The other result has already been evaluated before this method is
called; use andLazy to defer its computation.
Both value types and error types must match—for transformations, use
andThen instead.
Example:
Result<int, String> a = Ok(5);
Result<int, String> b = Ok(10);
final result = a.and(b); // Returns b (Ok(10))
Result<int, String> c = Err('failed');
final result2 = c.and(b); // Returns c (Err('failed')); b is ignored
Implementation
Result<T, E> and(Result<T, E> other) {
if (this is Err<T, E>) return this;
return other;
}