In Range§

See primary documentation in context for method minmax

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 $r1.is-int''$r2.is-int;                 # 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 $r3.is-int''$r4.is-int;                 # 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␤»

In Any§

See primary documentation in context for routine minmax

multi method minmax()
multi method minmax(&by)
multi        minmax(+args:&by!)
multi        minmax(+args)

Returns a Range from the smallest to the largest element.

If a Callable positional argument is provided, each value is passed into the filter, and its return value is compared instead of the original value. The original values are still used in the returned Range.

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).minmax();        # OUTPUT:«1..7␤» 
say (1,7,3).minmax({-$_});   # OUTPUT:«7..1␤» 
say minmax(1,7,3);           # OUTPUT: «1..7␤» 
say minmax(1,7,3,:by( -* )); # OUTPUT: «7..1␤»

In Operators§

See primary documentation in context for infix minmax

Returns the Range starting from the lowest to the highest of the values, as determined by the cmp semantics. For instance:

# numeric comparison 
10 minmax 3;     # 3..10 
 
# string comparison 
'10' minmax '3'# "10".."3" 
'z' minmax 'k';  # "k".."z" 

If the lowest and highest values coincide, the operator returns a Range made by the same value:

1 minmax 1;  # 1..1 

When applied to Lists, the operator evaluates the lowest and highest values among all available values:

(10,20,30minmax (0,11,22,33);       # 0..33 
('a','b','z'minmax ('c','d','w');   # "a".."z" 

Similarly, when applied to Hashes, it performs a cmp way comparison:

my %winner = points => 30misses => 10;
my %loser = points => 20misses => 10;
%winner cmp %loser;      # More 
%winner minmax %loser;
# ${:misses(10), :points(20)}..${:misses(10), :points(30)} 

In Supply§

See primary documentation in context for method minmax

method minmax(Supply:D: &custom-routine-to-use = &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.minmax.