or<F> method
Returns res
if the result is error, otherwise returns the ok value of class.
Arguments passed to or
are eagerly evaluated; if you are passing the
result of a function call, it is recommended to use orElse, which is
lazily evaluated.
Example
Basic Usage:
import 'package:dartsult/dartsult.dart';
main() {
Result<int, String> x = Result.ok(2);
Result<int, String> y = Result.error("late error");
assert(x.or(y) == Result.ok<int, String>(2));
x = Result.error("early error");
y = Result.ok(2);
assert(x.or(y) == Result.ok<int, String>(2));
x = Result.ok(2);
y = Result.ok(100);
assert(x.or(y) == Result.ok<int, String>(2));
}
Implementation
Result<T, F> or<F>(Result<T, F> res) {
if (_ok.val != null) {
return Result.ok(_ok.val!);
}
return res;
}