<div dir="ltr">That&#39;s a pretty nifty shorthand, although I don&#39;t personally think it adds enough on top of map to be worthwhile:<div><br></div><div><span style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)">let</span><span style="font-family:Menlo;font-size:11px"> makes = </span><span style="font-family:Menlo;font-size:11px;color:rgb(79,129,135)">cars</span><span style="font-family:Menlo;font-size:11px">*.make</span><br></div><div><span style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)">let</span><span style="font-family:Menlo;font-size:11px"> makes = </span><span style="font-family:Menlo;font-size:11px;color:rgb(79,129,135)">cars</span><span style="font-family:Menlo;font-size:11px">.map{$0.make}</span><span style="font-family:Menlo;font-size:11px"><br></span></div><div><br></div>My reasons:<div> * It adds new things to learn, and only saves 4 characters on map</div><div> * Perhaps I&#39;m missing your point, but your code example is also null safe, this doesn&#39;t seem to add an advantage.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 16, 2015 at 11:47 PM, Sean Kosanovich via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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">As a Groovy user, I really enjoy the shorthand Spread Operator over the Collect Closure (Map is the equivalent in Swift).<div><br></div><div>Consider the following Swift code:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">struct</span> Car {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:#bb2ca2">let</span> make: <span style="color:#703daa">String</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:#bb2ca2">let</span> model: <span style="color:#703daa">String</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">let</span> cars = [<span style="color:#4f8187">Car</span>(make: <span style="color:#d12f1b">&quot;Jeep&quot;</span>, model: <span style="color:#d12f1b">&quot;Grand Cherokee&quot;</span>), <span style="color:#4f8187">Car</span>(make: <span style="color:#d12f1b">&quot;Dodge&quot;</span>, model: <span style="color:#d12f1b">&quot;Challenger&quot;</span>)]</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">let</span> makes = <span style="color:#4f8187">cars</span>.<span style="color:#3d1d81">map</span>() { $0.<span style="color:#4f8187">make</span> }</div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div><div><div>Now consider the same code using a Spread Operator:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">let</span> makes = <span style="color:#4f8187">cars</span>*.make</div></div><div><br></div><div><br></div><div>The other distinction in Groovy is that the Spread Operator is null safe, meaning it won’t throw a NPE if an element is null, whereas the Collect Closure would.  So in Swift, I would propose the Spread Operator implicitly does this when operating on an array of Optionals:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">let</span> makes = <span style="color:#4f8187">cars</span>.<span style="color:#3d1d81">map</span>() { $0?.<span style="color:#4f8187">make</span> }</div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div></div><div style="margin:0px;line-height:normal">Thanks!</div><div style="margin:0px;line-height:normal">Sean</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=pQw7h83fWt3LLbgkfL4TSUL0weaZnVFZxDe5GShw4uT-2BnPhUyyIzxEkTwzgSaMC2J26s1ju2t6LtHd1a7cdBZ21zk8zdHMc80drgStdENSBVhGuYwzDl5y-2BNi-2Fk5gYb8wxlpS-2F2zpIpuRhakFMm8jZTLJkBCd9-2FodIqttfzkFqvSJoRA5vQ2Oc1AtyOe8p-2BswCICSPzVnMm8pTHxclsV60Z6BB3d3NPz1iOdVgOsNpA-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">
</div>
<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>