Enum Case KeyPaths

Could we piggyback on trailing ? syntax to disambiguate "opening" a particular case?

enum Color {
  case blue
  …
  var blue: Bool { … }
}

\Color.blue  // KeyPath<Color, Bool>
\Color.blue? // KeyPath<Color, Void?>

This syntax would hopefully fit in nicely with existing dot/optional-chaining syntax, and even pave the way for more general syntax outside of key/case paths:

let color = Color.generic("periwinkle")
color.generic?       // Optional("periwinkle")
color.generic?.count // Optional(10)

We could then even think of existing optional-chaining syntax as a "shorthand" where ? is the same as .some?.

12 Likes