|
The unary sort is useful for two reasons. It simplifies the code AND it does key caching. 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: ["A","b","C"].sort: { .lc } # A, b, C
["A","b","C"].sort: *.lc # same thing
Here's a custom sort: ["A","b","C"].sort: { $^b.lc leg $^a.lc } # C, b, A
Now combining them: ["A","b","C"].sort: *.lc, { $^b leg $^a } # C, b, A
The latter will run faster. |