Documentation for routine minmax

Documentation for routine minmax, assembled from the following types:

class Any

From Any

(Any) method minmax

Defined As:

multi method minmax(--> List:D)
multi method minmax(&by --> List:D)

Returns a list containing the smallest and the biggest element. If a Callable is provided each element is filtered and then numerically compared.


class Range

From Range

(Range) method minmax

Defined as:

multi method minmax(Range:D: --> List:D)

If the Range is an integer range (as indicated by is-int), then this method returns a list with the first and last value it will iterate over (taking into account excludes-min and excludes-max). If the range is not an integer range, the method will return a two element list containing the start and end point of the range unless either of excludes-min or excludes-max are True in which case a Failure is returned.

my $r1 = (1..5); my $r2 = (1^..5);
say $''$;                 # OUTPUT: «True, True␤» 
say $r1.excludes-min''$r2.excludes-min;     # OUTPUT: «False, True␤» 
say $r1.minmax''$r2.minmax;                 # OUTPUT: «(1 5), (2 5)␤» 
my $r3 = (1.1..5.2); my $r4 = (1.1..^5.2);
say $''$;                 # OUTPUT: «False, False␤» 
say $r3.excludes-max''$r4.excludes-max;     # OUTPUT: «False, True␤» 
say $r3.minmax;                                   # OUTPUT: «(1.1 5.2)␤» 
say $r4.minmax;
CATCH { default { put .^name''.Str } };
# OUTPUT: «X::AdHoc: Cannot return minmax on Range with excluded ends␤» 

class Supply

From Supply

(Supply) method minmax

method minmax(Supply:D: &by = &infix:<cmp> --> Supply:D)

Creates a supply that emits a Range every time a new minimum or maximum values is seen from the given supply. The optional parameter specifies the comparator, just as with Any.max.