<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><br><br><div id="AppleMailSignature">Sent from my iPhone</div><div><br>On Dec 21, 2017, at 2:33 PM, Ethan Diamond &lt;<a href="mailto:ethan.j.diamond@gmail.com">ethan.j.diamond@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 21, 2017, at 10:59 AM, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Dec 21, 2017, at 10:19 AM, Ethan Diamond &lt;<a href="mailto:ethanjdiamond@gmail.com" class="">ethanjdiamond@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Just to clarify, Dave -<div class=""><br class=""></div><div class="">What happens there if one case has associated values</div></div></div></blockquote></div><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">and one has an associated value thats an optional?&nbsp;</div><div class=""><br class=""></div><div class="">Enum A {</div><div class="">&nbsp; &nbsp;case x(String?)</div><div class="">&nbsp; &nbsp;case y</div><div class="">}</div><div class=""><br class=""></div><div class="">let a = A.x(nil)</div></div></div></blockquote><div class=""><br class=""></div>A.x is String??</div></div></div></blockquote><div><br class=""></div><div>This was assigning .x to a, not evaluating a synthesized value</div></div></div></blockquote><div><br></div>And I was making an assertion, not asking a question šŸ˜‰&nbsp;<br><blockquote type="cite"><div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">a.y // What's the result?</div></div></div></blockquote><div class=""><br class=""></div>nil as Optional&lt;Void&gt;</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">a.x // Would produce a double optional, which are clumsy to nil check</div></div></div></blockquote><div class=""><br class=""></div>Theyā€™re a fact of life. &nbsp;If thatā€™s a problem, we should consider fixing it, but itā€™s orthogonal to this one.</div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">I'm not a fan of solving this via synthesis in general. We have metatypes for classes/structs/protocols, which are useful in all sorts of situations. Cases are essentially "types" of enums. Why not have case metatypes? They're useful for the same reasons class types are, and there's already precedence in the language for syntax.</div></div></div></blockquote><div class=""><br class=""></div>You mean ā€œprecedent?ā€ &nbsp;OK, but I donā€™t see how it helps with any of the same problems as synthesized properties for cases do.</div><div class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>Iā€™m not really sure what the problems synthesized properties are trying to solve are. Chris brought them up as a possible solution to my pain point, which they only solve partially. Checking for a case I donā€™t know up front (for example, comparing the cases of two values) still isnā€™t covered.&nbsp;</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class=""><br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, Dec 21, 2017 at 7:14 AM Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class=""><span style="background-color:rgba(255,255,255,0)" class="">IIRC what we discussed was synthesizing &nbsp;members of type Optional&lt;Payload&gt; which could then be checked against nil.&nbsp;</span><div class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class="">if _ = x.failure { ... }</span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class="">if x.failure != nil { ... }</span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class="">if let r = x.success {...}</span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class=""><br class=""></span></div><div class=""><span style="background-color:rgba(255,255,255,0)" class="">IMO synthesizing predicates would be a huge missed opportunity by comparison</span><br class=""></div><br class=""><div id="m_-7614202654132317787AppleMailSignature" class="">Sent from my iPhone</div></div><div dir="auto" class=""><div class=""><br class="">On Dec 20, 2017, at 1:31 PM, Chris Lattner via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class="">In the past, weā€™ve discussed synthesizing predicate members onto enums.&nbsp; E.g. given:<div class=""><br class=""></div><div class="">enum E {</div><div class="">&nbsp; case X</div><div class="">&nbsp; case Y(Int)</div><div class="">}</div><div class=""><br class=""></div><div class="">youā€™d get something like:</div><div class=""><br class=""></div><div class="">extension E {</div><div class="">&nbsp; func isX() -&gt; Bool { return self == .X }</div><div class="">&nbsp; func getY() -&gt; Int? { ā€¦ }</div><div class="">}</div><div class=""><br class=""></div><div class="">which would solve the client side of this nicely.</div><div class=""><br class=""></div><div class="">-Chris</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 20, 2017, at 11:24 AM, Ethan Diamond via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_-7614202654132317787Apple-interchange-newline"><div class=""><div dir="ltr" class="">Sorry all for attaching the original post to the Non-Exhaustive enums thread. I"m moving it down to it's own thread.&nbsp;<div class=""><div class=""><br class=""></div><div class="">My understanding is I'm not allowed to write up a proposal unless I have the time to implement it. Is that still true? This is a major pain point for me to avoid having to write things like this:</div><div class=""><div class="">





<br class="m_-7614202654132317787webkit-block-placeholder"></div><p class="m_-7614202654132317787inbox-inbox-p1">if<span class="m_-7614202654132317787inbox-inbox-s1"> </span>case<span class="m_-7614202654132317787inbox-inbox-s1"> .</span><span class="m_-7614202654132317787inbox-inbox-s2">search</span><span class="m_-7614202654132317787inbox-inbox-s1"> = presenter.</span><span class="m_-7614202654132317787inbox-inbox-s2">state</span><span class="m_-7614202654132317787inbox-inbox-s1"> { </span>return<span class="m_-7614202654132317787inbox-inbox-s1"> </span>true<span class="m_-7614202654132317787inbox-inbox-s1"> } </span>else<span class="m_-7614202654132317787inbox-inbox-s1"> { </span>return<span class="m_-7614202654132317787inbox-inbox-s1"> </span>false<span class="m_-7614202654132317787inbox-inbox-s1"> }</span></p></div><div class="">Side note: Thanks Kevin, didn't know you could nest enums in switches like that. Super helpful!<br class=""></div><div class=""><br class=""></div><div class="">------------------------------------------------------</div><div class=""><pre style="white-space:pre-wrap" class="">I thought I would add another case that isnā€™t possible with current syntax (so far as Iā€™m aware).  You canā€™t negate the comparison to do something for all cases except a particular case.  You have to have an empty if block and use the else block, or have an empty case in a switch statement and use the default.

enum Enum {
  case a(param: String)
  case b(param: String)
  case c(param: String)
}

let enumeration: Enum = .a(param: "Hi")

if !(case .a = enumeration) {
  // Do something
}

ā€” Charles

&gt;<i class=""> On Dec 20, 2017, at 9:55 AM, Kevin Nattinger via swift-evolution &lt;<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">swift-evolution at swift.org</a>&gt; wrote:
</i>&gt;<i class=""> 
</i>&gt;<i class=""> I agree this would be useful. At the moment I have to hack around it with things like `var isFoo: Bool { if case .foo = self ā€¦`* with cases I commonly need, but this is definitely a feature that has come up before and I support. It is potentially related to getting the values through an accessor, which has also come up several times.
</i>&gt;<i class=""> 
</i>&gt;<i class=""> Sidenote, your `switch` example is actually trivial with existing syntax:
</i>&gt;<i class=""> 
</i>&gt;<i class=""> switch enumeration {
</i>&gt;<i class=""> case .a(.c(let param)): // or just .a(.c) if you don't need the value
</i>&gt;<i class="">     print(param)
</i>&gt;<i class=""> default:
</i>&gt;<i class="">     break
</i>&gt;<i class=""> }
</i>&gt;<i class=""> 
</i>&gt;<i class=""> I use this from time to time switching over, e.g., optional enums.
</i>&gt;<i class=""> 
</i>&gt;<i class=""> *: ugliest syntax ever, and it can't even be used as a standalone expression.
</i>&gt;<i class=""> 
</i>&gt;<i class=""> 
</i>&gt;&gt;<i class=""> On Dec 20, 2017, at 8:44 AM, Ethan Diamond via swift-evolution &lt;<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">swift-evolution at swift.org</a> &lt;mailto:<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">swift-evolution at swift.org</a>&gt;&gt; wrote:
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> Hello everyone,
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> One major pain point I've run into with Swift is the inability to evaluate the case of an enum that has associated values in a way that just returns a bool. We've been given the ability in a switch statement:
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> enum Enum {
</i>&gt;&gt;<i class="">    case a(param: String)
</i>&gt;&gt;<i class="">    case b(param: String)
</i>&gt;&gt;<i class=""> }
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> let enumeration: Enum = a(param: "Hi")
</i>&gt;&gt;<i class=""> switch enumeration {
</i>&gt;&gt;<i class="">     case a:
</i>&gt;&gt;<i class="">       // Do something
</i>&gt;&gt;<i class="">     case b:
</i>&gt;&gt;<i class="">       // Do something
</i>&gt;&gt;<i class=""> }
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> We'e been given the ability in the context of an if statement:
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> enum Enum {
</i>&gt;&gt;<i class="">    case a(param: String)
</i>&gt;&gt;<i class="">    case b(param: String)
</i>&gt;&gt;<i class=""> }
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> let enumeration: Enum = a(param: "Hi")
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> if case .a = enumeration { 
</i>&gt;&gt;<i class="">     // Do something
</i>&gt;&gt;<i class=""> }
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> But without a basic was of getting a bool for if an enum is a given case, here's a list of things I can't do:
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> Where statements:
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> enum Enum {
</i>&gt;&gt;<i class="">    case a(param: Enum2)
</i>&gt;&gt;<i class="">    case b(param: Enum2)
</i>&gt;&gt;<i class=""> }
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> enum Enum2 {
</i>&gt;&gt;<i class="">     case c(param: String)
</i>&gt;&gt;<i class="">     case d(param: String)
</i>&gt;&gt;<i class=""> }
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> let enumeration: Enum = a(param: "Hi")
</i>&gt;&gt;<i class=""> switch enumeration {
</i>&gt;&gt;<i class="">     case a(let inner) where [INNER CASE IS .c]
</i>&gt;&gt;<i class=""> }
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> ---------
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> Filter an array for a certain case:
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> Expertly explained by Erica Sadun here: <a href="http://ericasadun.com/2017/01/31/challenge-filtering-associated-value-enumeration-arrays/" target="_blank" class="">http://ericasadun.com/2017/01/31/challenge-filtering-associated-value-enumeration-arrays/</a> &lt;<a href="http://ericasadun.com/2017/01/31/challenge-filtering-associated-value-enumeration-arrays/" target="_blank" class="">http://ericasadun.com/2017/01/31/challenge-filtering-associated-value-enumeration-arrays/</a>&gt;
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> ---------
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> Nicely set a UIButton to hidden if an enum is a certain case:
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> enum State {
</i>&gt;&gt;<i class="">     case `default`
</i>&gt;&gt;<i class="">     case searching(results: [Result])
</i>&gt;&gt;<i class=""> }
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> myButton.isHidden = [STATE IS .searching]
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> ---------
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> I've run into this issue a ton of times because I tend to represent my views a State enums. I haven't seen anything on the board for plans for solving this issue, thought. Has there been any discussion about addressing it? Ideally I'd be able to do this:
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> enum Enum {
</i>&gt;&gt;<i class="">    case a(param: String)
</i>&gt;&gt;<i class="">    case b(param: String)
</i>&gt;&gt;<i class=""> }
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> let enumeration: Enum = a(param: "Hi")
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> case .a = enumeration // Bool
</i>&gt;&gt;<i class=""> case .a(let param) = enumeration // Bool, assigns "Hi" to "param"
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> Thanks!
</i>&gt;&gt;<i class=""> Ethan
</i>&gt;&gt;<i class=""> 
</i>&gt;&gt;<i class=""> _______________________________________________
</i>&gt;&gt;<i class=""> swift-evolution mailing list
</i>&gt;&gt;<i class=""> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">swift-evolution at swift.org</a> &lt;mailto:<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">swift-evolution at swift.org</a>&gt;
</i>&gt;&gt;<i class=""> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a>
</i>&gt;<i class=""> 
</i>&gt;<i class=""> _______________________________________________
</i>&gt;<i class=""> swift-evolution mailing list
</i>&gt;<i class=""> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">swift-evolution at swift.org</a>
</i>&gt;<i class=""> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></i></pre></div></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div></blockquote></div>
</div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></blockquote></body></html>