[swift-evolution] [Discussion] Sortable Attribute

Xiaodi Wu xiaodi.wu at gmail.com
Tue Aug 16 17:45:12 CDT 2016


On Tue, Aug 16, 2016 at 5:35 PM, Anton Zhilin <antonyzhilin at gmail.com>
wrote:

> What we need here is  sort_by  from Ruby. How about adding these overloads?
>
> func sort<U: Comparable>(by: (T) -> U)
> func sorted<U: Comparable>(by: (T) -> U) -> [T]
>

I'd be in favor. We'd need another name, since the current closure
predicate is already standardized to `by:`.
(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 }`.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160816/3d28e922/attachment.html>


More information about the swift-evolution mailing list