method collate

Documentation for method collate assembled from the following types:

class Any

From Any

(Any) method collate

Defined as:

method collate()

The collate method 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 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.

class Supply

From Supply

(Supply) method collate

method collate(Supply:D:)

Taps the Supply it is called on. Once that Supply emits done, all of the values that it emitted will be sorted taking into account Unicode grapheme characteristics. A new Supply is returned with the sorted values emitted. See Any.collate for more details on the collated sort.

my $s = Supply.from-list(<ä a o ö>);
my $t = $s.collate();
$t.tap(&say);           # OUTPUT: «a␤ä␤o␤ö␤»