<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">map would never be ambiguous in that case - since by definition map is a mapping of a set so it would never be able to deconstruct a sequence or array.<div class=""><br class=""></div><div class="">If they ever adopted said pattern matching in Swift - a separate function match or something would have to be implemented - but map would still continue to exist with case/default.</div><div class=""><br class=""></div><div class="">I have seen no proposals for pattern matching across an array/seq.</div><div class=""><br class=""></div><div class="">There is an example reduce in the proposal.</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 2016-01-18, at 9:21:41, Maximilian Hünenberger via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">See below</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="">Am 17.01.2016 um 20:05 schrieb Paul Ossenbruggen &lt;<a href="mailto:possen@gmail.com" class="">possen@gmail.com</a>&gt;:<br class=""><br class=""></div><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><div class=""><br class=""></div><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 17, 2016, at 10:07 AM, Maximilian Hünenberger via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class=""><div class=""></div><div class="">I totally agree with your statement that it should only be a short form of a single switch in a closure.</div><div class=""><div class=""><div class=""><div class=""><font class=""><span class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></font></div><div class="">I think only allowing expressions is too limiting so in case of writing `return` it can be omitted if there is only one expression after a case-label.&nbsp;</div></div></div></div></div></div></blockquote><div class=""><br class=""></div>I am fine with this idea. It would require that we check the number of lines in in the statement and produce an error or warning if there are more than one statement. This works especially well when the expression is on the same line as the label.</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class=""><div class=""><div class=""><div class=""><br class=""></div><div class="">Having more types which have a `map` function it seems that it could be handled with a protocol with a default implementation.</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; Concern: Also it could be easily confused with the `map` of collections where the closure doesn't take the collection itself but it's elements. Would be a new name like `mapElements` for collections considerable?</div></div></div></div></div></div></blockquote><div class=""><br class=""></div>We want to allow the higher order functions such as map, reduce on both containers and scalars. So on a collection it would perform the case mapping on each element in the collection. Unless I am misunderstanding what you are saying.&nbsp;</div><div class=""><br class=""></div></div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">If a switch statement can in future destruct a Sequence/Array the call of `map` would be ambiguous:</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">// [Int] mapped to<span class="Apple-converted-space">&nbsp;</span><b class="">one</b><span class="Apple-converted-space">&nbsp;</span>Int?</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">[1, 2, 3].map{</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">&nbsp; &nbsp; case let [x]: x</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span style="background-color: rgba(255, 255, 255, 0);" class="">case let [1, x]: x</span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">&nbsp; &nbsp;&nbsp;case let [1, 2, x]: x</span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">&nbsp; &nbsp; default: nil</span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">}</span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">// [Int] mapped to [Int] /<span class="Apple-converted-space">&nbsp;</span><b class="">multiple</b><span class="Apple-converted-space">&nbsp;</span>Int</span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">[1, 2, 3].map{</span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">&nbsp; &nbsp; case 1: 3</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">&nbsp; &nbsp;&nbsp;case 2: 2</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">&nbsp; &nbsp;&nbsp;case 3: 1</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">&nbsp; &nbsp; default: 0</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">}</span></div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">So in the latter example `map` could be renamed to `mapElements`.</span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">You said `reduce` could be used. Can you give an example how to use this?:</span></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">1234.reduce(...)</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">- Maximilian</div><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div dir="auto" class=""><div class=""><div class=""><div class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Should the ternary operator be removed in favor of:</div><div class=""><br class=""></div><div class="">(4 &lt; index).map{ cases true: 5, false: 7 }</div><div class="">// in comparison</div><div class="">4 &lt; index ? 5 : 7</div><div class=""><br class=""></div><div class="">I would<span class="Apple-converted-space">&nbsp;</span><b class="">not<span class="Apple-converted-space">&nbsp;</span></b>remove the ternary operator since it is "too" concise and useful for short expressions.</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; Otherwise since this is a short `switch` statement there could also be a short `if`:</div><div class=""><br class=""></div><div class="">// to be discussed</div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">(4 &lt; index).map{ 5 ||| 7 }</span></div><div class=""><br class=""></div><div class=""><br class=""></div></div></div></div></div></blockquote><br class=""></div><div class="">I was thinking something like this for the else. It is less than or greater than. It kind looks like a scale to make a decision.</div><div class=""><br class=""></div><div class=""><div dir="auto" class=""><div class=""><div class=""><div class=""><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">(4 &lt; index).map{ 5 &lt;&gt; 7 }</span></div></div></div></div></div><div class=""><div dir="auto" class=""><div class=""><div class=""><div class=""><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">Anyway, this is not much longer than:</span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">4 &lt; index ? 5 : 7</span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">But sure, we can keep ternary as is. Python generally tries to have one way to do things, &nbsp;Ruby goes to the other extreme of multiple ways to do the same thing.&nbsp;</span>I have heard no such argument made with Swift though. Swift does seem to more closely follow the Python philosophy because it allows breaking changes that can be fixed up with the conversion tools, but ternary may be the exception just because it has so much history around it.&nbsp;</div><div class=""><br class=""></div></div></div></div></div></div><blockquote type="cite" class=""><div dir="auto" class=""><div class=""><div class=""><div class=""><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">Because we are moving away from a ternary operator should this be discussed in a new thread?</span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">Like: Add short form of `switch` and `if` in closures</span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div></div></div></div></div></blockquote><br class="">Well, we are over 300 messages now, so why stop? Should be no problem for someone to get caught up. :-) Actually, maybe not a bad idea.&nbsp;</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class=""><div class=""><div class=""><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">- Maximilian</span></div></div></div></div><div class=""><br class="">Am 17.01.2016 um 18:00 schrieb Thorsten Seitz via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:<br class=""><br class=""></div><blockquote type="cite" class=""><div class="">Maybe I misread your proposed beginning, but the proposal should not be about introducing a new map method.&nbsp;<div class="">It introduces a new way of writing unary closures (i.e. closures taking one argument) with case clauses, i.e<div class=""><br class=""></div><div class="">instead of having to write</div><div class=""><br class=""></div><div class="">{ x in&nbsp;</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>switch x {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>case .Cold: return „Too cold“</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>case .Hot: return „Too hot“</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>default: return „Just right“</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div class="">}</div><div class=""><br class=""></div><div class="">we could just write</div><div class=""><br class=""></div><div class=""><div class="">{&nbsp;<span class="Apple-tab-span" style="white-space: pre;">        </span></div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>case .Cold: „Too cold“</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>case .Hot: „Too hot“</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>default: „Just right“</div><div class="">}</div><div class=""><br class=""></div><div class="">The case clauses may (or must?) be expressions instead of statements.</div><div class=""><br class=""></div><div class="">This will work with any higher order function, not just map, as the result is just a normal closure. No special version of „map“ needed.</div><div class=""><br class=""></div><div class="">-Thorsten</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class=""><blockquote type="cite" class=""><div class="">Am 17.01.2016 um 13:37 schrieb Charles Constant via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">It's better, but it still seems a bit dry to me. I tried rewriting the beginning. Is it better to start off like this?</div><div class=""><br class=""></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><div class=""><i class="">We are proposing a new “map” method. It directly addresses a “mapping” problem that pops up in almost all Swift programs, and currently has no elegant solution. The syntax we propose makes Swift code easier to read, easier to write, and less buggy.</i></div></div><div class=""><div class=""><i class=""><br class=""></i></div></div><div class=""><div class=""><i class="">Here is an example of the problem, where we want to assign a string mapped to an enum case:</i></div></div><div class=""><div class=""><i class=""><br class=""></i></div></div><div class=""><div class=""><i class=""><span class="" style="white-space: pre;">        </span>let str:String</i></div></div><div class=""><div class=""><span class="" style="white-space: pre;"><i class="">        </i></span></div></div><div class=""><div class=""><i class=""><span class="" style="white-space: pre;">        </span>switch state {</i></div></div><div class=""><div class=""><i class=""><span class="" style="white-space: pre;">        </span>case .Cold:&nbsp;</i></div></div><div class=""><div class=""><i class=""><span class="" style="white-space: pre;">                </span>str = “Too cold”</i></div></div><div class=""><div class=""><i class=""><span class="" style="white-space: pre;">        </span>case .Hot:&nbsp;</i></div></div><div class=""><div class=""><i class=""><span class="" style="white-space: pre;">                </span>str = “Too hot”</i></div></div><div class=""><div class=""><i class=""><span class="" style="white-space: pre;">        </span>default:&nbsp;</i></div></div><div class=""><div class=""><i class=""><span class="" style="white-space: pre;">                </span>str = “Just right”</i></div></div><div class=""><div class=""><i class=""><span class="" style="white-space: pre;">        </span>}</i></div></div><div class=""><div class=""><i class=""><br class=""></i></div></div><div class=""><div class=""><i class="">The syntax above does not elegantly express our intent. The “switch” statement is designed for “flow control”, but aside from choosing a single value, our example needs no “flow control”. Moreover, the ability to execute unrelated statements inside the “switch” encourages buggy code. Use of the “switch” statement for this task leads to bloated, confusing, error-prone code.</i></div></div></blockquote><div class=""><br class=""></div><div class="">Do you like it? It's all pretty subjective, I suppose.</div><div class=""><br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sat, Jan 16, 2016 at 8:51 PM, Craig Cruden<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:ccruden@novafore.com" target="_blank" class="">ccruden@novafore.com</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class="" style="word-wrap: break-word;">Forgot to include the link so people don’t need to search:<div class=""><br class=""></div><div class=""><a href="https://github.com/cacruden/swift-evolution/blob/master/proposals/0000-Pattern-Matching-Partial-Function.md" target="_blank" class="">https://github.com/cacruden/swift-evolution/blob/master/proposals/0000-Pattern-Matching-Partial-Function.md</a></div><div class=""><div class="h5"><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 2016-01-17, at 11:43:39, Craig Cruden &lt;<a href="mailto:ccruden@novafore.com" target="_blank" class="">ccruden@novafore.com</a>&gt; wrote:</div><br class=""><div class=""><div class="" style="word-wrap: break-word;">Updated the the motivation clause - not sure I am 100% there yet - but hopefully closer. &nbsp;<div class=""><br class=""></div><div class="">As well as a few minor updates to things like let on reduce example and clarifying that the partial closures can use the optional return keyword.</div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 2016-01-15, at 4:16:56, Charles Constant &lt;<a href="mailto:charles@charlesism.com" target="_blank" class="">charles@charlesism.com</a>&gt; wrote:</div><br class=""><div class=""><div dir="ltr" class="">Hi Craig,<div class=""><br class=""></div><div class="">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.&nbsp;</div><div class=""><br class=""></div><div class="">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 class="">"Motivation" could be clearer for those of our peers who haven't followed the thread.&nbsp;<br class=""></div><div class=""><br class=""></div><div class="">The motivation, from my point of view:</div><div class="">- 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 &nbsp;</div><div class="">- 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 class="">- using the existing "switch" to do this is less safe, because unrelated code can be inserted in the case statements<br class=""></div><div class="">- current alternatives to "switch" aren't good (e.g.: using a Dict has quirks that add the cognitive load)</div><div class="">- this new "map" method can make code less verbose, easier to read, and safer</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Jan 14, 2016 at 11:23 AM, Craig Cruden<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:ccruden@novafore.com" target="_blank" class="">ccruden@novafore.com</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class="">Paul,&nbsp;</div><div class=""><br class=""></div>I tried to put my understanding on the latest proposal option into a draft on github (instead of my usual BitBucket repo). &nbsp;<div class=""><br class=""></div><div class="">Take a look at it and see if there is anything useable.</div><div class=""><br class=""></div><div class=""><a href="https://github.com/cacruden/swift-evolution/blob/master/proposals/0000-Pattern-Matching-Partial-Function.md" target="_blank" class="">https://github.com/cacruden/swift-evolution/blob/master/proposals/0000-Pattern-Matching-Partial-Function.md</a></div><span class=""><font color="#888888" class=""><div class=""><br class=""></div><div class="">Craig</div></font></span><div class=""><div class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 2016-01-11, at 14:17:09, Craig Cruden &lt;<a href="mailto:ccruden@novafore.com" target="_blank" class="">ccruden@novafore.com</a>&gt; wrote:</div><br class=""><div class=""><div class="" style="word-wrap: break-word;">Ignore the last comment - tired and mistaken. :p<div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 2016-01-11, at 14:16:01, Craig Cruden &lt;<a href="mailto:ccruden@novafore.com" target="_blank" class="">ccruden@novafore.com</a>&gt; wrote:</div><br class=""><div class=""><div class="" 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. &nbsp;<div class=""><br class=""></div><div class="">If the switch / case can do that , the partial function case should be able to do the same thing.</div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 2016-01-11, at 13:23:19, Craig Cruden &lt;<a href="mailto:ccruden@novafore.com" target="_blank" class="">ccruden@novafore.com</a>&gt; wrote:</div><br class=""><div class=""><div class="" style="word-wrap: break-word;"><div class="">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). &nbsp;</div><div class=""><br class=""></div><div class="">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&nbsp;complete&nbsp;function (exhaustive) can be passed (e.g. reduce, filter, etc.) - otherwise they might get confused on why we are adding it to “map”. &nbsp;</div><div class=""><br class=""></div><div class="">The optional where clause should also be part of the case clause as part of the proposal. &nbsp;</div><div class=""><br class=""></div><div class="">There would be no need for statement based “fallthrough”.</div><div class=""><br class=""></div><div class="">You mentioned your proposal…. &nbsp;have you drafted a formal proposal draft?</div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 2016-01-10, at 12:41:03, Paul Ossenbruggen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class="">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:&nbsp;<div class=""><br class=""></div><div class=""><div class=""><div dir="ltr" class=""><div class="" style="word-wrap: break-word;"><div dir="ltr" class=""><div class="" style="word-wrap: break-word;"><div dir="ltr" class=""><div class="" style="font-size: 13px; margin: 0px; line-height: normal; font-family: Arial;"><b class=""><div dir="ltr" class="" style="font-family: Helvetica; font-size: 12px; font-weight: normal;"><div class="" style="word-wrap: break-word;"><div dir="ltr" class=""><div class="" style="word-wrap: break-word;"><div dir="ltr" class=""><b class="" style="font-family: Arial; font-size: 13px;"><b class=""><span class="" style="color: rgb(96, 96, 96); white-space: pre-wrap;">        </span><font color="#006d8f" class="">let</font></b><b class="" style="color: rgb(96, 96, 96);">&nbsp;num =&nbsp;color.</b><font color="#008cb4" class="">map&nbsp;</font>{</b></div></div></div></div></div></b></div></div></div></div></div></div></div></div></div></blockquote><blockquote type="cite" class=""><b class="" style="font-family: Arial; font-size: 13px;"><b class="" style="color: rgb(96, 96, 96);"><span class="" style="white-space: pre-wrap;">        </span></b><b class=""><span class="" style="white-space: pre-wrap;"><font color="#606060" class="">        </font><font color="#006d8f" class="">cases</font><font color="#606060" class="">   </font></span></b><b class=""><font color="#4f7a28" class="">.Red:</font></b><b class="" style="color: rgb(227, 36, 0);">&nbsp;</b><b class="" style="color: rgb(96, 96, 96);">100,</b><b class="" style="color: rgb(96, 96, 96);">&nbsp;</b></b><br class=""><b class="" style="font-family: Arial; font-size: 13px;"><b class="" style="color: rgb(96, 96, 96);"><span class="" style="white-space: pre-wrap;">        </span></b><b class=""><span class="" style="white-space: pre-wrap;"><font color="#606060" class="">        <span class="" style="white-space: pre-wrap;">        </span>     </font><font color="#4f7a28" class="">.</font></span></b><b class=""><font color="#4f7a28" class="">Green:&nbsp;</font></b><span class="">&nbsp;</span><b class="" style="color: rgb(96, 96, 96);">200</b><b class=""><font color="#e32400" class="">,</font></b><b class="" style="color: rgb(96, 96, 96);">&nbsp;</b></b><br class=""><b class="" style="font-family: Arial; font-size: 13px;"><b class="" style="color: rgb(96, 96, 96);"><span class="" style="white-space: pre-wrap;">        </span></b><b class="" style="color: rgb(96, 96, 96);"><span class="" style="white-space: pre-wrap;">        <span class="" style="white-space: pre-wrap;">        </span>     </span></b><b class=""><font color="#4f7a28" class="">.Blue</font><font color="#e32400" class="">:&nbsp;</font></b><b class="" style="color: rgb(96, 96, 96);">300</b></b><br class=""><b class="" style="font-family: Arial; font-size: 13px;"><b class="" style="color: rgb(96, 96, 96);"><span class="" style="white-space: pre-wrap;">        </span></b><b class=""><span class="" style="white-space: pre-wrap;"><font color="#606060" class="">        </font><font color="#006d8f" class="">default</font></span></b><b class="" style="color: rgb(227, 36, 0);">:&nbsp;</b><b class="" style="color: rgb(96, 96, 96);">-1</b><b class="" style="color: rgb(227, 36, 0);">&nbsp;</b></b><br class=""><b class="" style="font-family: Arial; font-size: 13px;"><span class="" style="color: rgb(227, 36, 0); white-space: pre-wrap;">        </span>}</b><br class=""><b class="" style="font-family: Arial; font-size: 13px;"><b class=""><span class="" style="color: rgb(96, 96, 96); white-space: pre-wrap;">        </span><font color="#006d8f" class="">let</font></b><b class="" style="color: rgb(96, 96, 96);">&nbsp;num =&nbsp;color.</b><b class=""><font color="#008cb4" class="">map&nbsp;</font>{</b></b><br class=""><b class="" style="font-family: Arial; font-size: 13px;"><b class="" style="color: rgb(96, 96, 96);"><span class="" style="white-space: pre-wrap;">        </span></b><b class=""><span class="" style="white-space: pre-wrap;"><font color="#606060" class="">        </font><font color="#006d8f" class="">case</font><font color="#606060" class="">     </font></span></b><b class=""><font color="#4f7a28" class="">.Red:</font></b><b class="" style="color: rgb(227, 36, 0);">&nbsp;</b><b class="" style="color: rgb(96, 96, 96);">100</b></b><br class=""><b class="" style="font-family: Arial; font-size: 13px;"><b class="" style="color: rgb(96, 96, 96);"><span class="" style="white-space: pre-wrap;">        </span></b><b class=""><span class="" style="white-space: pre-wrap;"><font color="#606060" class="">        </font><font color="#006d8f" class="">case   </font><font color="#606060" class="">  </font><font color="#4f7a28" class="">.</font></span></b><b class=""><font color="#4f7a28" class="">Green:&nbsp;</font></b><span class="" style="font-family: Helvetica;">&nbsp;</span><b class="" style="color: rgb(96, 96, 96);">200</b><b class="" style="color: rgb(96, 96, 96);">&nbsp;</b></b><br class=""><b class="" style="font-family: Arial; font-size: 13px;"><b class="" style="color: rgb(96, 96, 96);"><span class="" style="white-space: pre-wrap;">        </span></b><b class=""><span class="" style="white-space: pre-wrap;"><font color="#606060" class="">        </font><font color="#006d8f" class="">case</font><font color="#606060" class="">     </font></span></b><b class=""><font color="#4f7a28" class="">.Blue</font><font color="#e32400" class="">:&nbsp;</font></b><b class="" style="color: rgb(96, 96, 96);">300</b></b><br class=""><b class="" style="font-family: Arial; font-size: 13px;"><b class="" style="color: rgb(96, 96, 96);"><span class="" style="white-space: pre-wrap;">        </span></b><b class=""><span class="" style="white-space: pre-wrap;"><font color="#606060" class="">        </font><font color="#006d8f" class="">default</font></span></b><b class="" style="color: rgb(227, 36, 0);">:&nbsp;</b><b class="" style="color: rgb(96, 96, 96);">-1</b><b class="" style="color: rgb(227, 36, 0);">&nbsp;</b></b><br class=""><div class="" style="word-wrap: break-word;"><div class=""><div class=""><div class=""><div class=""><div class="" style="word-wrap: break-word;"><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class="" style="word-wrap: break-word;"><div class=""><div class=""><div class=""><div dir="ltr" class=""><div class="" style="word-wrap: break-word;"><div dir="ltr" class=""><div class="" style="word-wrap: break-word;"><div dir="ltr" class=""><div class="" style="font-size: 13px; margin: 0px; line-height: normal; font-family: Arial;"><b class=""><span class="" style="color: rgb(227, 36, 0); white-space: pre-wrap;">        </span>}</b></div><div class=""><b class=""><br class=""></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 class=""></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></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" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></blockquote><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></div></blockquote></div><br class=""></div></body></html>