<html><body 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=""> <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=""> <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=""> </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. 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></body></html>