2016-08-17 1:45 GMT+03:00 Xiaodi Wu <[email protected]>:

> On Tue, Aug 16, 2016 at 5:35 PM, Anton Zhilin <[email protected]>
> 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.
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to