max
ErrorsCollection

max

Synthesised documentation from type/Supply type/Range type/Any language/operators

From type/Supply

See Original text in context

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.

From type/Range

See Original text in context

method max(Range:D:)

Returns the end point of the range.

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

From type/Any

See Original text in context

multi method max()
multi method max(&by)
multi sub max(+args:&by!)
multi sub max(+args)

Coerces the invocant to Iterable and returns the numerically largest element; in the case of Hashes, the Pair with the highest value.

If a Callable positional argument is provided, each value is passed into the filter, and the return value is compared instead of the original value. The original value is still the one returned from max.

In sub form, the invocant is passed as an argument and a comparison Callable can be specified with the named argument :by.

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␤»

From language/operators

See Original text in context

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»