<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span></span></div><div><div>I think you could say something along these lines... The standard conditional value in the ternary operator is being replaced with an inserted value that can be of any equatable (possibly comparable) type. While the "true:false" portion of the ternary operator will be replaced with case:value pairs of which will be used to compare the case to the inserted value and return the value from the matched pair. <br><br>Jo<div><br></div><div>Sent from my iPhone</div></div><div><br>On Jan 14, 2016, at 4:29 PM, Charles Constant via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">That was my attempt, maybe a poor one, at expressing what we're trying to do. I guess another way to express it is that we're "mapping" but only mapping one possible value.<div><div><br></div><div>Maybe "domain" isn't the best choice of words, but fwiw I meant, say for the "ternary expression":</div><div><div><br></div><div>let result = boo ? "it worked" : "it failed"</div></div><div><br></div><div><div>I was thinking that what we're doing is kind of this:</div></div><div><br></div><div>Domain A is "Boolean Values", which can be: "true" or "false"</div><div>Domain B is "Status Strings", which can be "It worked" or "it failed"</div><div><br></div><div>So our ternary maps the states of our bool to the states of our strings, and uses the value as a key. Does that make sense? Well, maybe not :)</div><div><br></div><div><br></div><div><br></div><div><br><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 14, 2016 at 1:21 PM, Craig Cruden <span dir="ltr"><<a href="mailto:ccruden@novafore.com" target="_blank">ccruden@novafore.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Thanks, <div><br></div><div><span class=""><blockquote type="cite"><div dir="ltr"><div>- the need to use a value from one domain, as a "key" to another is very common. The ternary is a special case of this, and for all it's flaws, it's a very popular expression in multiple languages </div></div></blockquote><div><br></div></span><div>This one I am not quite sure what you are saying with this one - can you expand it a bit so I understand the key selling point? The rest of the points I understand.</div><div><div class="h5"><br><div><blockquote type="cite"><div>On 2016-01-15, at 4:16:56, Charles Constant <<a href="mailto:charles@charlesism.com" target="_blank">charles@charlesism.com</a>> wrote:</div><br><div><div dir="ltr">Hi Craig,<div><br></div><div>Well done, what you wrote looks pretty good to me. I had no trouble understanding the proposal. It's a good length, too - I think the shorter we can make it, the more appealing it is. </div><div><br></div><div>The only section that I think needs improvement is "Motivation." I think we could sell it better. I know when I've read some of the other proposals, I do it in fairly cursory way.</div><div>"Motivation" could be clearer for those of our peers who haven't followed the thread. <br></div><div><br></div><div>The motivation, from my point of view:</div><div>- the need to use a value from one domain, as a "key" to another is very common. The ternary is a special case of this, and for all it's flaws, it's a very popular expression in multiple languages </div><div>- using the existing "switch" to do this is bloated (more so in Swift because you have to declare the variable before the switch statement)</div><div>- using the existing "switch" to do this is less safe, because unrelated code can be inserted in the case statements<br></div><div>- current alternatives to "switch" aren't good (e.g.: using a Dict has quirks that add the cognitive load)</div><div>- this new "map" method can make code less verbose, easier to read, and safer</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 14, 2016 at 11:23 AM, Craig Cruden <span dir="ltr"><<a href="mailto:ccruden@novafore.com" target="_blank">ccruden@novafore.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Paul, </div><div><br></div>I tried to put my understanding on the latest proposal option into a draft on github (instead of my usual BitBucket repo). <div><br></div><div>Take a look at it and see if there is anything useable.</div><div><br></div><div><a href="https://github.com/cacruden/swift-evolution/blob/master/proposals/0000-Pattern-Matching-Partial-Function.md" target="_blank">https://github.com/cacruden/swift-evolution/blob/master/proposals/0000-Pattern-Matching-Partial-Function.md</a></div><span><font color="#888888"><div><br></div><div>Craig</div></font></span><div><div><div><br><div><blockquote type="cite"><div>On 2016-01-11, at 14:17:09, Craig Cruden <<a href="mailto:ccruden@novafore.com" target="_blank">ccruden@novafore.com</a>> wrote:</div><br><div><div style="word-wrap:break-word">Ignore the last comment - tired and mistaken. :p<div><br></div><div><br><div><blockquote type="cite"><div>On 2016-01-11, at 14:16:01, Craig Cruden <<a href="mailto:ccruden@novafore.com" target="_blank">ccruden@novafore.com</a>> wrote:</div><br><div><div style="word-wrap:break-word">I just realized “cases” probably is not needed - if it see’s a comma after case but before “:” then it is the concise form. <div><br></div><div>If the switch / case can do that , the partial function case should be able to do the same thing.</div><div><br></div><div><br><div><blockquote type="cite"><div>On 2016-01-11, at 13:23:19, Craig Cruden <<a href="mailto:ccruden@novafore.com" target="_blank">ccruden@novafore.com</a>> wrote:</div><br><div><div style="word-wrap:break-word"><div>I have thought about it a bit more and I think this would cover all the cases that interest me (in addition to others needs for a little more conciseness on the most simple case). </div><div><br></div><div>I also think we need to be clear that the “case” (or cases) and “default” are is really just a partial function which in it’s entirety is really just a complete function for used wherever a complete function (exhaustive) can be passed (e.g. reduce, filter, etc.) - otherwise they might get confused on why we are adding it to “map”. </div><div><br></div><div>The optional where clause should also be part of the case clause as part of the proposal. </div><div><br></div><div>There would be no need for statement based “fallthrough”.</div><div><br></div><div>You mentioned your proposal…. have you drafted a formal proposal draft?</div><div><br></div><div><br></div><br><div><blockquote type="cite"><div>On 2016-01-10, at 12:41:03, Paul Ossenbruggen via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div>I agree that it would be really useful to keep things concise. I am going to suggest again an idea I had in the past, it is also in my proposal, which might work well for this problem. This might address the verbosity of the “case” and at the same time make it obvious we are dealing with a switch expression. So both would be valid: <div><br></div><div><div><div dir="ltr"><div style="word-wrap:break-word"><div dir="ltr"><div style="word-wrap:break-word"><div dir="ltr"><div style="font-size:13px;margin:0px;line-height:normal;font-family:Arial"><b><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-weight:normal"><div style="word-wrap:break-word"><div dir="ltr"><div style="word-wrap:break-word"><div dir="ltr"><b style="font-family:Arial;font-size:13px"><b><span style="color:rgb(96,96,96);white-space:pre-wrap">        </span><font color="#006d8f">let</font></b><b style="color:rgb(96,96,96)"> num = color.</b><font color="#008cb4">map </font>{</b></div></div></div></div></div></b></div></div></div></div></div></div></div></div></div></blockquote><blockquote type="cite"><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">cases</font><font color="#606060"> </font></span></b><b><font color="#4f7a28">.Red:</font></b><b style="color:rgb(227,36,0)"> </b><b style="color:rgb(96,96,96)">100,</b><b style="color:rgb(96,96,96)"> </b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        <span style="white-space:pre-wrap">        </span> </font><font color="#4f7a28">.</font></span></b><b><font color="#4f7a28">Green: </font></b><span> </span><b style="color:rgb(96,96,96)">200</b><b><font color="#e32400">,</font></b><b style="color:rgb(96,96,96)"> </b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        <span style="white-space:pre-wrap">        </span> </span></b><b><font color="#4f7a28">.Blue</font><font color="#e32400">: </font></b><b style="color:rgb(96,96,96)">300</b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">default</font></span></b><b style="color:rgb(227,36,0)">: </b><b style="color:rgb(96,96,96)">-1</b><b style="color:rgb(227,36,0)"> </b></b><br><b style="font-family:Arial;font-size:13px"><span style="color:rgb(227,36,0);white-space:pre-wrap">        </span>}</b><br><b style="font-family:Arial;font-size:13px"><b><span style="color:rgb(96,96,96);white-space:pre-wrap">        </span><font color="#006d8f">let</font></b><b style="color:rgb(96,96,96)"> num = color.</b><b><font color="#008cb4">map </font>{</b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">case</font><font color="#606060"> </font></span></b><b><font color="#4f7a28">.Red:</font></b><b style="color:rgb(227,36,0)"> </b><b style="color:rgb(96,96,96)">100</b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">case </font><font color="#606060"> </font><font color="#4f7a28">.</font></span></b><b><font color="#4f7a28">Green: </font></b><span style="font-family:Helvetica"> </span><b style="color:rgb(96,96,96)">200</b><b style="color:rgb(96,96,96)"> </b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">case</font><font color="#606060"> </font></span></b><b><font color="#4f7a28">.Blue</font><font color="#e32400">: </font></b><b style="color:rgb(96,96,96)">300</b></b><br><b style="font-family:Arial;font-size:13px"><b style="color:rgb(96,96,96)"><span style="white-space:pre-wrap">        </span></b><b><span style="white-space:pre-wrap"><font color="#606060">        </font><font color="#006d8f">default</font></span></b><b style="color:rgb(227,36,0)">: </b><b style="color:rgb(96,96,96)">-1</b><b style="color:rgb(227,36,0)"> </b></b><br><div style="word-wrap:break-word"><div><div><div><div><div style="word-wrap:break-word"><div><div><div><div><div><div><div><div style="word-wrap:break-word"><div><div><div><div dir="ltr"><div style="word-wrap:break-word"><div dir="ltr"><div style="word-wrap:break-word"><div dir="ltr"><div style="font-size:13px;margin:0px;line-height:normal;font-family:Arial"><b><span style="color:rgb(227,36,0);white-space:pre-wrap">        </span>}</b></div><div><b><br></b></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote></div><br></div></div></blockquote></div><br></div></div></div></blockquote></div><br></div></div></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>
</div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ZKcnqA3HtCYQN0SS0ldgu8hd-2BX5-2FVe6JJMt0-2F4G77utiz2rp150TWU5l1NgHFGkUQSZF9rc4ch3Cdd7dp1qK9w6FvfytZQz1wlgRhgf7nlm8nVeG1Oprj6iUGWIPPe-2BamxWzzRzSZyXC-2F7RMfV29KF8K1Im-2Bv1uzhDfn8Gm11Hkv4EdFC2GNc6Ytn0mPiaSJv8gS7wYihlfV2HZ8KNGEQA-3D-3D" alt="" width="1" height="1" border="0" style="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;">
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></body></html>