<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-08-17 1:45 GMT+03:00 Xiaodi Wu <span dir="ltr"><<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="h5"><div class="gmail_extra"><div class="gmail_quote">On Tue, Aug 16, 2016 at 5:35 PM, Anton Zhilin <span dir="ltr"><<a href="mailto:antonyzhilin@gmail.com" target="_blank">antonyzhilin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">What we need here is sort_by from Ruby. How about adding these overloads?<div><br></div><div><font face="monospace, monospace">func sort<U: Comparable>(by: (T) -> U)</font></div><div><font face="monospace, monospace">func sorted<U: Comparable>(by: (T) -> U) -> [T]</font></div></div>
</blockquote></div><br></div></div></div><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 class="gmail_extra">(Or, as I propose above, once `Ordering` comes to the stdlib, we can just have it as `func sort<U: Comparable>(_ ordering: Ordering, by: (T) -> U)`, called like `sort(.ascending) { $0.age }`.)</div></div></blockquote><div><br></div><div>Agreed, because we wouldn't be able to perform a descending sort otherwise.</div></div></div></div>