method collate

Documentation for method collate assembled from the following types:

class Any

From Any

(Any) method collate

Defined as:

method collate()

Collate sorts taking into account Unicode grapheme characteristics; that is, sorting more or less as one would expect instead of using the order in which their codepoints appear. collate will behave this way if the object it is applied to is Iterable.

say ('a''Z').sort# (Z a) 
say ('a''Z').collate# (a Z) 
say <ä a o ö>.collate# (a ä o ö) 
my %hash = 'aa' => 'value''Za' => 'second';
say %hash.collate# (aa => value Za => second); 

This method is affected by the $*COLLATION variable, which configures the four collation levels. While the Primary, Secondary and Tertiary mean different things for different scripts, for the Latin script used in English they mostly correspond with Primary being Alphabetic, Secondary being Diacritics and Tertiary being Case.

In the example below you can see how when we disable tertiary collation which in Latin script generally is for case, and also disable quaternary which breaks any ties by checking the codepoint values of the strings, we get Same back for A and a:

$*COLLATION.set(:quaternary(False), :tertiary(False));
say 'a' coll 'A'#OUTPUT: «Same␤» 
say ('a','A').collate == ('A','a').collate# OUTPUT: «True␤»

The variable affects the coll operator as shown as well as this method.