[swift-evolution] sortBy, minElementBy and maxElementBy methods

Brent Royal-Gordon brent at architechies.com
Thu Dec 31 14:20:43 CST 2015


> I don’t get the resistance to Dave’s solution? I think it works well and much more applicable.

I have two issues:

1. It's less discoverable. Someone merely *typing* `sort` into their editor will see `sortBy` right below it in their autocompletion list, and might discover it that way.

2. It forces a naïve implementation, which may not be the best idea. In the Perl world, for instance, we would usually use a Schwartzian transform to implement this, particularly if the key might be expensive to compute:

	array.map { ($0, sortKey($0)) }.sort { $0.1 < $1.1 }.map { $0.0 }

Having said that, I think both of these concerns are relatively  minor.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list