@steven099
It seems like, if ’break with value’ is a general feature, and there’s Ok wrapping, then break should actually represent the success case.
I don’t know of a case where break does ok-wrapping.
In which case, you want something really clear like fail to represent the error case (fail matches try {}).
With fail, and a new keyword pass for ok-wrapping:
let _: Result<Foo, Bar> = routine {
foo()?; // ? operator
fail Bar(0); // assign Err(Bar(0)) to _
fail Baz(0); // assigns Err(Bar(x)) to _ after error conversion
pass Foo(0); // assign Ok(Foo(0)) to _
Foo(0) // assign Ok(Foo(0)) to _
}
// ...
This seems to have worse cohesion than the earlier blocks, I can’t think of a name for ? in this pattern, and it explicitly returns to an error handling construct. On the other hand, it can’t be argued that it behaves anything like traditional exceptions.
There may be a way to tie in with the pass/fail terms:
let _: Result<Foo, Bar> = eval { // like "evaluation"
foo()?; // try operator
fail Bar(0);
pass Foo(0);
Foo(0)
}
// ...
Since evaluate and try have similar meaning in this context, they can be swapped:
let _: Result<Foo, Bar> = try {
foo()?; // evaluate operator
fail Bar(0);
pass Foo(0);
Foo(0)
}
// ...