[swift-evolution] [Discussion] Sortable Attribute
Anton Zhilin
antonyzhilin at gmail.com
Tue Aug 16 17:50:48 CDT 2016
2016-08-17 1:45 GMT+03:00 Xiaodi Wu <xiaodi.wu at gmail.com>:
> 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 }`.)
>
Agreed, because we wouldn't be able to perform a descending sort otherwise.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160817/d23023f5/attachment.html>
More information about the swift-evolution
mailing list