<div dir="ltr">I've wanted similar too. Although it may be better, instead of Bool, to have it as an optional tuple, the reason I suggest this is so that you can get the associated type. For example:<div><br></div><div>case let .Link(value,link) = self<br><div><div><br></div><div>So your example could be written:</div><div><br><div><div style="font-size:13px">func isEmpty() -> Bool {</div><div style="font-size:13px"> return (case .Empty = self) != nil</div><div style="font-size:13px">}</div></div><div style="font-size:13px"><br></div><div style="font-size:13px">However I'm not sure about this syntax, perhaps something like this:</div></div></div></div><div style="font-size:13px"><br></div><div style="font-size:13px"><div><div>func isEmpty() -> Bool {</div><div> return self is case .Empty</div><div>}</div></div><div><br></div></div><div style="font-size:13px">Alternatively if you want the value you could do:</div><div style="font-size:13px"><br></div><div style="font-size:13px">let (value, link) = self as? case .Link</div><div style="font-size:13px"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 8, 2015 at 3:05 PM, Alex Lew via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>Curious to hear thoughts on allowing non-binding pattern matches to be used as boolean values outside of an if, guard, for...in, while, switch, etc. Something like:</div><div><br></div><div>enum List<T> {</div><div> case Empty</div><div> indirect case Link(T, List<T>)</div><div> </div><div> func isEmpty() -> Bool {</div><div> return case .Empty = self</div><div> }</div><div>}</div><div><br></div><div>It gets rid of some boilerplate (explicit return true and return false), and seems intuitive that it would work given that you can already do </div><div><br></div><div>if case .Empty = self {</div><div> return true</div><div>} else {</div><div> return false</div><div>}</div><div><br></div><div>I haven't really thought through all the implications here, so there's probably something I'm missing. It also may be useful only in such limited situations that it's not worth the trouble to add.</div><div><br></div><div>-Alex</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=pQw7h83fWt3LLbgkfL4TSUL0weaZnVFZxDe5GShw4uQKig8LXmLi-2FUsCzoi5yRXiPxzHDvc4wSqEwQaEi7TJV4y5h2e3qczvNTeVB9QPt4seuH2cHkii9-2BunUbImKtSt5gP9CaQyn-2BVofjJ8S5Y1CTjT7zhQcJrruz5l-2FPWli-2FR-2BtMAUvVQ7NUy2fIsoAWPO-2BTNuUEBi56gBSBbPRiNyGIHXsLDmNE9hkpo0loQIJBk-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>