<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">Idea: Consolidate the Code for Each Case in an Enum</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;"># Motivation:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">Consolidate all code related to a single enum case in one spot. This makes it easier to ensure that all the pieces mesh coherently across that one case.</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;"># Background:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">Enum cases _feel_ like separately defined, but tightly related structs because each case can have distinct associated values. They have special privileges that a family of structs doesn't have, like `self = .otherCase`. Enums are really awesome.</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;"># Proposed Solution:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">Any `func` or dynamic `var` that provides a unique response per `case` uses a `switch` to do so. I propose to hide that standard `switch` behind some syntactic sugar. Possibly `extension MyEnum.myCase`, assuming that nothing extra is allowed there (protocol conformance, generic constraints, etc.).</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">Here's a typical example of a (simplified) enum that represents 2 states, and conforms to 2 protocols, each requiring different dynamic values based on the case of the enum. In both places, an outer `switch` is used to select the current enum case, and the logic within each branch further determines the value returned.</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">```</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">protocol State {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; mutating func react(to event: Event)</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">enum TokenState: State, CustomStringConvertible {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; case expired(at: Date)</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; case validated(token: String)</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; var description: String {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; switch self {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; case let .expired(at):</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return "Expired at \(at)"</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; case let .validated(token):</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return "Token \(token) has been validated."</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; mutating func react(to event: Event) {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; switch self {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; case .expired:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch event {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case _ as TokenRefreshed:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self = .validated(token: event.token)</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; case .validated:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch event {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case _ as TokenRejected:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self = .expired(at: Date())</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case _ as UserLoggedOut:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self = .expired(at: Date())</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; min-height: 13.8px;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp;&nbsp; &nbsp;</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">```</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">If we instead allow all the code for each enum case to be consolidated, this new code looks much more like the rest of the code we write in Swift. Real world enums frequently have many more cases, and as the number of enum cases grows consolidating all their logic is increasingly helpful. The following proposal is identical to the code above, it simply "hides" the outer switch statement of each value.</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">```</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">enum TokenState: State, CustomStringConvertible {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; case expired(at: Date)</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; case validated(token: String)</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">extension TokenState.expired {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; var description: String {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; return "Token expired at \(<a href="http://self.at">self.at</a>)"</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; min-height: 13.8px;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp;&nbsp;</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; mutating func react(to event: Event) {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; switch event {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; case _ as TokenRefreshed:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self = .untested(token: event.token)</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; default:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">extension TokenState.validated {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; min-height: 13.8px;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp;&nbsp;</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; var description: String {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; return "Token \(self.token) has been validated."</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; min-height: 13.8px;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp;&nbsp;</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; mutating func react(to event: Event) {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; switch event {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; case _ as TokenRejected:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self = .expired(at: Date())</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; case _ as UserLoggedOut:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self = .expired(at: Date())</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; default:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; min-height: 13.8px;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp;&nbsp; &nbsp;</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">```</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">I've also shown automatic binding of each case's associated values to properties available on `self` ... but maybe it's better if they're bound to variable references captured the way a closure does. I'm not an expert in this part.</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">Back to the meat of the idea, what happens when a case isn't extended, or only partially extended? Because it's simply a fancy `switch`, it still must be exhaustive or provide a `default` branch.</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">```</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">extension TokenState.expired {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; var description: String {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; return "Token expired at \(<a href="http://self.at">self.at</a>)"</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial; min-height: 13.8px;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp;&nbsp;</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &lt;&lt;&lt; error: react(to:) must be exhaustively defined. Missing implementation for case .expired</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">```</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">Can be mitigated with:</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">```</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">enum TokenState: State, CustomStringConvertible {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; case expired(at: Date)</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; case validated(token: String)</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; // This becomes the `default` branch in the generated `switch`</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; mutating func react(to event: Event) {</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; &nbsp; &nbsp; print("Ignoring \(event) in case \(self)")</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">&nbsp; &nbsp; }</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">}</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">```</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">​</span></p>
<p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initial;"><span style="font-size: 12pt; -webkit-font-kerning: none;">Note that this implementation for the `default` branch is just that. This is not creating a superclass/subclass relationship between the `enum` and the `case`, it's merely a convenient way to construct a `switch` statement. I'm not proposing to deprecate any existing source, merely introduce a more convenient form of a very typical pattern, so I hope it is source-compatible by the definition you guys are using.</span></p><div><span style="font-size: 12pt; -webkit-font-kerning: none;"><br></span></div><div><span style="font-size: 12pt; -webkit-font-kerning: none;">Thoughts?</span></div><br><div>--Tim</div></div></body></html>