Correct me if I am wrong but currently there are only two ways to extract the value of an associated type.<br><br>// 1<br>switch n {<br>case foo(let value):<br>print(value)<br>}<br><br>// 2<br>if case foo(let value) = n {<br>  print(value)<br>}<br><br>I think it would be nice to have another way.  Maybe a tuple-like pattern.<br><br>let value = n.foo.0 // returns value as an optional.<br><br>If this can already be done, ignore me.<br><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Jan 8, 2017 at 2:20 AM Robert Widmann via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="gmail_msg"><div class="gmail_msg">I don&#39;t think I&#39;ve ever wanted to distribute the patterns of a switch statement across multiple files.  It seems like you want an enum of enums if the code you&#39;re writing needs this kind of chunking.  Distributing cases is also far more brittle than the existing local switch; failing to include a file in the build that covers necessary cases now becomes a module-level error rather than a statement-local one.  Finally, the proposal seems to do the opposite of consolidate and simplify code by introducing quite a lot of syntax around what it aims to do, and by muddying the meaning of a keyword that was previously only meant for types.</div><div id="m_3382415464585266790AppleMailSignature" class="gmail_msg"><br class="gmail_msg"></div><div id="m_3382415464585266790AppleMailSignature" class="gmail_msg">A few conceptual questions:</div><div id="m_3382415464585266790AppleMailSignature" class="gmail_msg"><br class="gmail_msg"></div><div id="m_3382415464585266790AppleMailSignature" class="gmail_msg">How does this interact with versioned cases?  </div><div id="m_3382415464585266790AppleMailSignature" class="gmail_msg">What about enums that carry values?<br class="gmail_msg"><br class="gmail_msg">~Robert Widmann</div><div class="gmail_msg"><br class="gmail_msg">2017/01/06 23:59、Tim Shadel via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; のメッセージ:<br class="gmail_msg"><br class="gmail_msg"></div></div><div dir="auto" class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">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" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg"># Motivation:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">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" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg"># Background:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">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&#39;t have, like `self = .otherCase`. Enums are really awesome.</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg"># Proposed Solution:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">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" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">Here&#39;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" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">```</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">protocol State {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    mutating func react(to event: Event)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">}</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">enum TokenState: State, CustomStringConvertible {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    case expired(at: Date)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    case validated(token: String)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    var description: String {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">      switch self {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        case let .expired(at):</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            return &quot;Expired at \(at)&quot;</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        case let .validated(token):</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            return &quot;Token \(token) has been validated.&quot;</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">      }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    mutating func react(to event: Event) {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        switch self {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        case .expired:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            switch event {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            case _ as TokenRefreshed:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">                self = .validated(token: event.token)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            default:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">                break</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        case .validated:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            switch event {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            case _ as TokenRejected:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">                self = .expired(at: Date())</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            case _ as UserLoggedOut:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">                self = .expired(at: Date())</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            default:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">                break</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;min-height:13.8px" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    </span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">}</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">```</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">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 &quot;hides&quot; the outer switch statement of each value.</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">```</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">enum TokenState: State, CustomStringConvertible {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    case expired(at: Date)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    case validated(token: String)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">}</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">extension TokenState.expired {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    var description: String {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">      return &quot;Token expired at \(<a href="http://self.at" class="gmail_msg" target="_blank">self.at</a>)&quot;</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;min-height:13.8px" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">  </span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    mutating func react(to event: Event) {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        switch event {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        case _ as TokenRefreshed:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            self = .untested(token: event.token)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        default:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            break</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">}</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">extension TokenState.validated {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;min-height:13.8px" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">  </span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    var description: String {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">      return &quot;Token \(self.token) has been validated.&quot;</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;min-height:13.8px" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">  </span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    mutating func react(to event: Event) {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        switch event {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        case _ as TokenRejected:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            self = .expired(at: Date())</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        case _ as UserLoggedOut:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            self = .expired(at: Date())</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        default:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">            break</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;min-height:13.8px" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    </span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">}</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">```</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">I&#39;ve also shown automatic binding of each case&#39;s associated values to properties available on `self` ... but maybe it&#39;s better if they&#39;re bound to variable references captured the way a closure does. I&#39;m not an expert in this part.</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">Back to the meat of the idea, what happens when a case isn&#39;t extended, or only partially extended? Because it&#39;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" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">```</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">extension TokenState.expired {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    var description: String {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">      return &quot;Token expired at \(<a href="http://self.at" class="gmail_msg" target="_blank">self.at</a>)&quot;</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;min-height:13.8px" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">  </span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    &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" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">}</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">```</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">Can be mitigated with:</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">```</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">enum TokenState: State, CustomStringConvertible {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    case expired(at: Date)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    case validated(token: String)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    // This becomes the `default` branch in the generated `switch`</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    mutating func react(to event: Event) {</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">        print(&quot;Ignoring \(event) in case \(self)&quot;)</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">    }</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">}</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">```</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">​</span></p>
<p style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica" class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">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&#39;s merely a convenient way to construct a `switch` statement. I&#39;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 class="gmail_msg"><span style="font-size:12pt" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg"><span style="font-size:12pt" class="gmail_msg">Thoughts?</span></div><br class="gmail_msg"><div class="gmail_msg">--Tim</div></div></div></blockquote><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><span class="gmail_msg">_______________________________________________</span><br class="gmail_msg"><span class="gmail_msg">swift-evolution mailing list</span><br class="gmail_msg"><span class="gmail_msg"><a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a></span><br class="gmail_msg"><span class="gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class="gmail_msg"></div></blockquote></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>