<div style="white-space:pre-wrap">I think you would be able to define such an operator if .make was recognized as Car.make in the Car context. <br>Which would be a cool addition to current rules. </div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 16, 2015 at 18:15 Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> 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">You can already define an infix operator that does this. Are you proposing one be in the standard library? I would be opposed to adding new syntax for this.</div><div style="word-wrap:break-word"><div><br><div><blockquote type="cite"><div>On Dec 16, 2015, at 6:47 AM, Sean Kosanovich via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><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">"Jeep"</span>, model: <span style="color:#d12f1b">"Grand Cherokee"</span>), <span style="color:#4f8187">Car</span>(make: <span style="color:#d12f1b">"Dodge"</span>, model: <span style="color:#d12f1b">"Challenger"</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=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAfkeFtVq-2FDeSmmAYj-2BuVuR1g89wRc5MoRMEjEuWCtVc1QwaKyj4n0sOecI8nrdkYJAV7wj8DrW0zh8gjNR5Xa3hBTABQSPOR-2B-2BrDaS-2BXneVq8bIf45zTqzntJlv-2BFYQbFBD9ryWTPeXWhdkshOPQjNiOHFsqyVgPu-2FpJWvYdmLg6lxoJNhPb-2Frq1Qmn08Yfj7g-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>swift-evolution mailing list<br><a href="mailto: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>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1p9Jer2O6jVE9KWvo-2B9iUaEyN8slp4IizyiLwsfp54PIO4JSFoZEtx5rx473JQwkq-2BVy0wVbNAgTU-2B9Bv-2BeG1-2Fs-2FuSnlD5fQACfnajzpO8Olsbc9WEPli4eMtJtw3AqB9C9YMVOOI-2Fb08FD7A5iVXPJYdRuxUei-2F63t2-2FMPSoR2wU4ZsS0v901CKy7Rivic2fwMhr5AWgOrlfrMsVeELR3Uru-2B3KO8m2RmxO7XijdgE-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>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">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>
</blockquote></div>