orElse

Undocumented in source. Be warned that the author may not have intended to support it.
ref
orElse
(
alias pred
T
E
)
(
return auto ref scope Result!(T, E) result
)
if (
is(typeof(pred(E.init)) == Result!(T, E))
)

Examples

// source: https://doc.rust-lang.org/std/result/enum.Result.html#method.or_else
alias R = Result!(int, int);

auto sqr = delegate R(int x) => (x * x).ok;
auto keep = delegate R(int x) => x.err;

assert(R.ok(2).orElse!sqr.orElse!sqr == 2.ok);
assert(R.ok(2).orElse!keep.orElse!sqr == 2.ok);
assert(R.err(3).orElse!sqr.orElse!keep == 9.ok);
assert(R.err(3).orElse!keep.orElse!keep == 3.err);

Meta