|
|
|
|
|
by yxhuvud
4564 days ago
|
|
Somehow I prefer the Ruby solution to add another method to do the unary variant. Compare ["A","b","C"].sort {|a, b| a.downcase <=> b.downcase }
to ["A","b","C"].sort_by {|k| k.downcase }
(or equivalently) ["A","b","C"].sort_by &:downcase
|
|
But sometimes you need BOTH a key extraction closure (to get key caching for performance) AND a comparison closure (to specify a custom sort). In P6 you just specify both closures (P6 figures out which is which because one has one arg and the other has two).
Here's the P6 equivalent of your last couple lines:
Here's a custom sort: Now combining them: The latter will run faster.