[swift-evolution] Switch on an optional enum -- `case: nil`?

Eric Miller hi at simple.gy
Thu May 5 10:40:20 CDT 2016


Wondering if you guys think this is a reasonable idea.

I was switching on an optional enum today, and naturally gravitated towards
including nil as a case:

enum Coin {
  case heads
  case tails
}
var result: Coin?

switch result {
case heads: print("heads")
case tails: print("tails")
case nil: print("not yet flipped") // exhaustive
}

Doesn't compile, and of course I can if-let or guard to unwrap instead, but
I like the compactness of this.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160505/c968c155/attachment.html>


More information about the swift-evolution mailing list