routine minmax
1 | language documentation Operators |
1.1 | (Operators) infix minmax |
2 | class Supply |
2.1 | (Supply) method minmax |
3 | class Range |
3.1 | (Range) method minmax |
4 | class Any |
4.1 | (Any) method minmax |
Documentation for routine minmax
assembled from the following types:
language documentation Operators
From Operators
(Operators) 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 Lists, 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 Hashes, 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)}
class Supply
From Supply
(Supply) 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.
class Range
From Range
(Range) method minmax
Defined as:
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»
class Any
From Any
(Any) method minmax
Defined as:
multi method minmax()multi method minmax()multi sub minmax(+args, :!)multi sub 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
.
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»