Comparing enums without their associated values

In many places (if, guard, switch, etc.) you can already do this:

if case .bar = test {
    // ...
}

But it would be nice to have a shorter way of assigning the result or passing it to a function parameter, because this is tedious:

let isEqualWithoutItsAssocValues = { if case .bar = test { return true } else { return false } }()

The idea of synthesized properties of the form var isBar: Bool has also come up. That is another way of solving the same problem:

let isEqualWithoutItsAssocValues = test.isBar
2 Likes