If values and objects were made Collections of exactly one value then you could write:<div><br></div><div> let str = state.flatMap {</div><div> switch $0 {</div><div> case .Cold: return "Too cold"</div><div> case .Hot: return "Too hot"</div><div> default: return "now it's just boring"</div><div> }</div><div> }<br><br>This would be purely a library solution which is a lot easier to implement and has the advantage of then giving real use data to see if people actually use the facility.</div><div><br>On Sunday, 31 January 2016, Craig Cruden via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> 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>The case partial functions are available in all closures, plus you still have the option to write your syntax based on the proposal with the only difference being the keyword of match vs switch.</div><div><br></div><div>let str = match(state) {</div><div><span style="white-space:pre-wrap">        </span>case .Cold: “Too cold”</div><div><span style="white-space:pre-wrap">        </span>case .Hot: “Too hot”</div><div><span style="white-space:pre-wrap">        </span>default: “now it is just boring”</div><div>}</div><div><br></div><div>match just being a function that takes a value and a closure.</div><div><br></div><div><br></div><div><br></div><br><div><blockquote type="cite"><div>On 2016-01-31, at 2:11:20, Radosław Pietruszewski via swift-evolution <<a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div style="word-wrap:break-word"><div>I certainly would prefer if we could use switch (and if/else for that matter) as an expression, instead of some magic syntax usable in `map`. so:</div><div><br></div><div>let str = switch(state) {</div> case .Cold: "Too cold"<br> case .Hot: "Too hot"<br> default: "Just right"<br> }<div><br><div><br><div>
<div>— Radek</div>
</div>
<br><div><blockquote type="cite"><div>On 29 Jan 2016, at 08:10, Paul Cantrell via swift-evolution <<a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On Jan 29, 2016, at 1:01 AM, Charles Constant via swift-evolution <<a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div dir="ltr"><div class="gmail_extra">I'm still +1 on this.</div><div class="gmail_extra"><br></div><div class="gmail_extra">I would very much enjoy being able to do this:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div style="margin-bottom:16px;color:rgb(51,51,51);line-height:25.6px"><pre style="white-space:pre-wrap;overflow:auto;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;background-color:rgb(247,247,247)"><div style="margin:0px;line-height:normal;color:rgb(167,29,93);min-height:16px"><font face="Menlo"><span style="font-size:11px"><span>let</span><span style="color:rgb(50,51,51)"> str = state.</span><span>map</span><span style="color:rgb(50,51,51)"> {</span><br></span></font></div><div style="margin:0px;line-height:normal;color:rgb(50,51,51)"><font face="Menlo"><span style="font-size:11px"><span style="white-space:pre-wrap">        </span><span style="color:rgb(167,29,93)">case</span> <span style="color:rgb(167,29,93)">.</span>Cold: <span style="white-space:pre-wrap">        </span>“Too cold”</span></font></div><div style="margin:0px;line-height:normal;color:rgb(50,51,51)"><font face="Menlo"><span style="font-size:11px"><span style="color:rgb(167,29,93)"><span style="white-space:pre-wrap">        </span>case</span> <span style="color:rgb(167,29,93)">.</span>Hot: <span style="white-space:pre-wrap">        </span>“Too hot”</span></font></div><div style="margin:0px;line-height:normal;color:rgb(50,51,51)"><font face="Menlo"><span style="font-size:11px"><span style="color:rgb(167,29,93)"><span style="white-space:pre-wrap">        </span>default</span>: <span style="white-space:pre-wrap">        </span>“Just right”</span></font></div><div style="margin:0px;line-height:normal;color:rgb(50,51,51)"><font face="Menlo"><span style="font-size:11px">}</span></font></div></pre></div></div></div></div></blockquote></div><div><br></div><div>The language currently allows this:</div><br><div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><div style="margin:0px;font-size:10.5px;line-height:normal"> <span style="color:#323e7d">let</span> str: <span style="color:#587ea8">String</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"> <span style="color:#323e7d">switch</span>(<span style="color:#587ea8">state</span>) {</div><div style="margin:0px;font-size:10.5px;line-height:normal"> <span style="color:#323e7d">case</span> .Cold: <span style="color:#587ea8">str</span> = <span style="color:#843e64">"Too cold"</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"> <span style="color:#323e7d">case</span> .Hot: <span style="color:#587ea8">str</span> = <span style="color:#843e64">"Too hot"</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"> <span style="color:#323e7d">default</span>: <span style="color:#587ea8">str</span> = <span style="color:#843e64">"Just right"</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"> }</div><div><br></div></div></div><div><div>While that’s slightly noisier, I’m not convinced the minor additional concision justifies the substantial additional language complexity. I’m not even convinced the new syntax is clearer so much as cleverer.</div><div><br></div><div>I’d need to see a much more compelling example to be in favor of this proposal.</div></div><div><br></div><div>Cheers,</div><div><br></div><div>Paul</div><div><br></div><div><br></div></div>_______________________________________________<br>swift-evolution mailing list<br><a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></div>_______________________________________________<br>swift-evolution mailing list<br><a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></blockquote></div><br><br>-- <br> -- Howard.<br><br>