In Operators§

See primary documentation in context for infix max

Returns the largest of the arguments, as determined by cmp semantics.

my $foo = -42;
$foo max= 0   # read as: $foo increases to 0

Note: Before 2022.06, in the cases of ties &max would return the first argument with that value, whereas &[max] would return its RHS. After 2022.06, &[max] returns its LHS in the case of ties, and now both return the same value as dictated by their List associativity.

say max 0False# OUTPUT: «0␤» 
say 0 max False;  # OUTPUT: «0␤» 
say max False0# OUTPUT: «False␤» 
say False max 0;  # OUTPUT: «False␤»

In Supply§

See primary documentation in context for method max

method max(Supply:D: &custom-routine-to-use = &infix:<cmp> --> Supply:D)

Creates a supply that only emits values from the given supply if they are larger than any value seen before. In other words, from a continuously ascending supply it will emit all the values. From a continuously descending supply it will only emit the first value. The optional parameter specifies the comparator, just as with Any.max.

In Range§

See primary documentation in context for method max

method max(Range:D:)

Returns the end point of the range.

say (1..5).max;                                   # OUTPUT: «5␤» 
say (1^..^5).max;                                 # OUTPUT: «5␤»

In Any§

See primary documentation in context for routine max

multi method max(&by?:$k:$v:$kv:$p )
multi sub max(+args:&by:$k:$v:$kv:$p)

The interface of the max method / routine is the same as the one of min. But instead of the lowest value, it will return the highest value, obviously.

say (1,7,3).max();                # OUTPUT: «7␤» 
say (1,7,3).max({1/$_});          # OUTPUT: «1␤» 
say max(1,7,3,:by{ 1/$_ } ));   # OUTPUT: «1␤» 
say max(1,7,3);                   # OUTPUT: «7␤» 
max( %(=> 'B'b=> 'C' ) ).say# OUTPUT: «b => C␤»

As of the 2023.08 Rakudo compiler release:

say <a b c c>.max(:k);  # OUTPUT:«(2 3)␤» 
say <a b c c>.max(:v);  # OUTPUT:«(c c)␤» 
say <a b c c>.max(:kv); # OUTPUT:«(2 c 3 c)␤» 
say <a b c c>.max(:p);  # OUTPUT:«(2 => c 3 => c)␤»