<div dir="ltr">FWIW, I&#39;m not convinced that making enum values look like structs with optional properties for the union of all their cases is a good idea. It&#39;s certainly not something I would want added to all of my enums by default, and it feels IMO like it&#39;s just an awkward hack around the fact that pattern matching is a bit verbose in some scenarios because Swift doesn&#39;t provide a case-expression to let you test/bind as part of a larger expression.<div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jan 18, 2017 at 10:08 AM Andy Chou 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 style="word-wrap:break-word" class="gmail_msg">That’s an interesting proposal. Here’s a link for reference:  <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160926/027287.html" class="gmail_msg" target="_blank">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160926/027287.html</a><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The one thing is the proposed syntax doesn’t handle enum cases without payloads. I think that could be handled by an optional Void, so this comment in the original proposal:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">&gt; <span style="white-space:pre-wrap;background-color:rgb(255,255,255)" class="gmail_msg">Only enum cases with a payload can be used with this syntax (it would make no sens for cases without a payload).</span></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Would be changed to allow for empty payloads turning into Void?. For example:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div dir="ltr" class="gmail_msg"><div class="m_7906877240715178628markdown-here-wrapper gmail_msg"><pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin-top:1.2em;margin-bottom:1.2em" class="gmail_msg"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;background-color:rgb(248,248,248);overflow:auto;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important" class="gmail_msg">enum Result {
    case success(Int)
    case failure
}

let r: Result = foo()

let x: Int? = r.success
let y: Void? = r.failure

assert(r.success == Optional(42))
assert(r.failure == nil)</code></pre></div></div></blockquote><div class="gmail_msg">I think it’s a reasonable compromise, though I still think it’s a bit awkward for the common case. Looks like this is being postponed for now, so we’ll have to live with the alternatives.</div></div><div class="gmail_msg"></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Andy</div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Jan 18, 2017, at 12:20 AM, Anton Zhilin &lt;<a href="mailto:antonyzhilin@gmail.com" class="gmail_msg" target="_blank">antonyzhilin@gmail.com</a>&gt; wrote:</div><br class="m_7906877240715178628Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg"><div class="m_7906877240715178628markdown-here-wrapper gmail_msg"><p style="margin:0px 0px 1.2em!important" class="gmail_msg">AFAICS, Andy needs not default implementations of Equatable, but cases-as-optional-properties—this topic has also been discussed on the list.</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px" class="gmail_msg"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important" class="gmail_msg">enum Result {
    case success(Int)
    case failure(String)
}

let r: Result = foo()

let x: Int? = r.success
let y: String? = r.failure

assert(r.success == Optional(42))
assert(r.failure == nil)
</code></pre><div title="MDH:QUZBSUNTLCBBbmR5IG5lZWRzIG5vdCBkZWZhdWx0IGltcGxlbWVudGF0aW9ucyBvZiBFcXVhdGFi
bGUsIGJ1dCBjYXNlcy1hcy1vcHRpb25hbC1wcm9wZXJ0aWVzLS10aGlzIHRvcGljIGhhcyBhbHNv
IGJlZW4gZGlzY3Vzc2VkIG9uIHRoZSBsaXN0LjxkaXY+PGJyPjwvZGl2PjxkaXY+YGBgPC9kaXY+
PGRpdj5lbnVtIFJlc3VsdCB7PC9kaXY+PGRpdj4mbmJzcDsgJm5ic3A7IGNhc2Ugc3VjY2VzcyhJ
bnQpPC9kaXY+PGRpdj4mbmJzcDsgJm5ic3A7IGNhc2UgZmFpbHVyZShTdHJpbmcpPC9kaXY+PGRp
dj59PC9kaXY+PGRpdj48YnI+PC9kaXY+PGRpdj5sZXQgcjogUmVzdWx0ID0gZm9vKCk8L2Rpdj48
ZGl2Pjxicj48L2Rpdj48ZGl2PmxldCB4OiBJbnQ/ID0gci5zdWNjZXNzPC9kaXY+PGRpdj5sZXQg
eTogU3RyaW5nPyA9IHIuZmFpbHVyZTwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+YXNzZXJ0KHIu
c3VjY2VzcyA9PSBPcHRpb25hbCg0MikpPGJyPjwvZGl2PjxkaXY+YXNzZXJ0KHIuZmFpbHVyZSA9
PSBuaWwpPC9kaXY+PGRpdj5gYGA8L2Rpdj4=" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0" class="gmail_msg">​</div></div></div>
</div></blockquote></div><br class="gmail_msg"></div></div></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>