In Supply§
See primary documentation in context for method minmax
method minmax(Supply: = :<cmp> --> Supply)
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.
In Range§
See primary documentation in context for method minmax
multi method minmax(Range: --> List)
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 = (1..5); my = (1^..5);say .is-int, ', ', .is-int; # OUTPUT: «True, True»say .excludes-min, ', ', .excludes-min; # OUTPUT: «False, True»say .minmax, ', ', .minmax; # OUTPUT: «(1 5), (2 5)»my = (1.1..5.2); my = (1.1..^5.2);say .is-int, ', ', .is-int; # OUTPUT: «False, False»say .excludes-max, ', ', .excludes-max; # OUTPUT: «False, True»say .minmax; # OUTPUT: «(1.1 5.2)»say .minmax;CATCH ;# 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()multi minmax(+args, :!)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 comparison10 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 List
s, the operator evaluates the lowest and highest values among all available values:
(10,20,30) minmax (0,11,22,33); # 0..33('a','b','z') minmax ('c','d','w'); # "a".."z"
Similarly, when applied to Hash
es, it performs a cmp way comparison:
my = points => 30, misses => 10;my = points => 20, misses => 10;cmp ; # Moreminmax ;# ${:misses(10), :points(20)}..${:misses(10), :points(30)}