I had an idea about this, and I’m still not sure if it’s brilliant or terrible.
Basically, we already have this:
if (a()) {
// boolean true
} else {
// boolean false
}
if (a()) |cap| {
// optional
} else {
// null case
}
if (a()) |cap| {
// error, you can tell because
} else |err| {
// there's second capture
}
Which are all syntactically distinct, that’s an important trait IMHO.
Well, why not take it a bit further?
if (!a()) {
// is a null case because:
} else |cap| {
// it has an else-capture but no if-capture,
// it has a `!` as well. Sometimes the capture
// branch is long, and you want to, say, return
// from the null case first, y'know?
}
if (a()) |opt_cap| {
// oh no! an error and an optional!
// this is the happy path where you get something
} else {
// here's that null branch
} else |err| {
// and here's the error
// yep. double else. mantatory, double, else
}
So a !?T
while
loop would be
while (can_error.next()) |cap| {
// do stuff
} else {
// must have a null case but it can be empty,
// and it breaks the while loop
} else |err| {
// error case, also breaks the while loop
}
The saving grace of this is that a double-else is illegal, except for a condition which is !?T
, in which case, it is mandatory.