<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="">You can already define an infix operator that does this. &nbsp;Are you proposing one be in the standard library? &nbsp;I would be opposed to adding new syntax for this.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 16, 2015, at 6:47 AM, Sean Kosanovich 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="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">As a Groovy user, I really enjoy the shorthand Spread Operator over the Collect Closure (Map is the equivalent in Swift).<div class=""><br class=""></div><div class="">Consider the following Swift code:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span> Car {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> make: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> model: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> cars = [<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Car</span>(make: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Jeep"</span>, model: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Grand Cherokee"</span>), <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Car</span>(make: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Dodge"</span>, model: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Challenger"</span>)]</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> makes = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">cars</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">map</span>() { $0.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">make</span> }</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div class=""><div class="">Now consider the same code using a Spread Operator:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> makes = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">cars</span>*.make</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">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. &nbsp;So in Swift, I would propose the Spread Operator implicitly does this when operating on an array of Optionals:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> makes = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">cars</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">map</span>() { $0?.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">make</span> }</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div></div><div style="margin: 0px; line-height: normal;" class="">Thanks!</div><div style="margin: 0px; line-height: normal;" class="">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="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;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>