Proposal draft for `is case` (pattern-match boolean expressions)

I think it would be useful especially if it could be composed with where to make further refining pattern matches in switch/case or for/in statements. I'd move the let after the case though:

if either is case let .a(payload) { ... }

The example from that other thread I linked above would turn into:

switch firstEnum {
case let .firstCase(firstStruct)
     where firstStruct.secondEnum is case let .secondCase(secondStruct),
           secondStruct.id == someOtherId:
    ...
default:
    ...
}

But I guess that would mean there'd be a new way to write the existing if case/let:

if firstEnum is case let .firstCase(firstStruct),
   firstStruct.secondEnum is case let .secondCase(secondStruct),
   secondStruct.id == someOtherId
{
    ...
}
4 Likes