<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Haskell also has a `comparing` function</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; comparing&nbsp;:: (Ord a) =&gt; (b -&gt; a) -&gt; b -&gt; b -&gt; Ordering</font></div><div class=""><br class=""></div><div class="">which applies a function on both the left hand side and the right hand side to get two values that can be compared/ordered.&nbsp;</div><div class="">This makes the call site look something like this:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; sortBy (comparing length) names</font></div><div class=""><br class=""></div><div class="">The same&nbsp;<i class="">can</i>&nbsp;be done in Swift, resulting in a similar and very English-like calls site:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; names.sort(by: comparing { $0.characters.count })</font></div><div class=""><br class=""></div><div class="">That said. While this (the `comparing` function) is a fun exercise in higher order functions, a more Swifty syntax for this is probably a separate overload of the sort/ed/&nbsp;function.</div><div class=""><br class=""></div><div class="">- David</div><br class=""><div><blockquote type="cite" class=""><div class="">On 17 Aug 2016, at 02:17, Silvan Mosberger 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=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class=""></div><blockquote type="cite" class=""><div dir="ltr" class=""><div class="gmail_extra">I'd be in favor. We'd need another name, since the current closure predicate is already standardized to `by:`.</div></div></blockquote><br class=""><div class="">Haskell uses "on" for sorting with a mapping. There are both</div><div style="direction: inherit;" class=""><br class=""></div><div style="direction: inherit;" class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><a id="v:sortOn" class="def" style="margin: 0px; padding: 0px; font-weight: bold;">sortOn</a>&nbsp;::&nbsp;<a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Ord.html#t:Ord" style="margin: 0px; padding: 0px; text-decoration: none;" class="">Ord</a>&nbsp;b =&gt; (a -&gt; b) -&gt; [a] -&gt; [a]</span></font></div><div style="direction: inherit;" class=""><br class=""></div><div style="direction: inherit;" class="">and</div><div style="direction: inherit;" class=""><br class=""></div><div style="direction: inherit;" class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><a id="v:sortBy" class="def" style="margin: 0px; padding: 0px; font-weight: bold;">sortBy</a>&nbsp;:: (a -&gt; a -&gt;&nbsp;<a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Ord.html#t:Ordering" style="margin: 0px; padding: 0px; text-decoration: none;" class="">Ordering</a>) -&gt; [a] -&gt; [a]</span></font></div><div style="direction: inherit;" class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></font></div><div style="direction: inherit;" class=""><font class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">in Haskell.</span></font></div></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=""></body></html>