In Any§

See primary documentation in context for routine min

multi method min(&by?, :$k, :$v, :$kv, :$p )
multi        min(+args, :&by, :$k, :$v, :$kv, :$p)

Coerces the invocant to Iterable and returns the smallest element using cmp semantics; in the case of Maps and Hashes, it returns the Pair with the lowest value.

A Callable positional argument can be given to the method form. If that Callable accepts a single argument, then it will be used to convert the values to be sorted before doing comparisons. The original value is still the one returned from min.

If that Callable accepts two arguments, it will be used as the comparator instead of cmp.

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

say (1,7,3).min();              # OUTPUT: «1␤»
say (1,7,3).min({1/$_});        # OUTPUT: «7␤»
say min(1,7,3);                 # OUTPUT: «1␤»
say min(1,7,3,:by( { 1/$_ } )); # OUTPUT: «7␤»
min( %(a => 3, b=> 7 ) ).say ;  # OUTPUT: «a => 3␤»

As of the 2023.08 Rakudo compiler release, additional named arguments can be specified to get all possible information related to the lowest value. Whenever any of these named arguments is specified, the returned value will always be a List.

  • :k

Returns a List with the indices of the lowest values found.

  • :v

Returns a List with the actual values of the lowest values found. In the case of a Map or Hash, these would the Pairs.

  • :kv

Returns a List with the index and the value alternating.

  • :p

Returns a List of Pairs in which the key is the index value, and the value is the actual lowest value (which in the case of a Map or a Hash would be a Pair).

say <a b c a>.min(:k);  # OUTPUT:«(0 3)␤»
say <a b c a>.min(:v);  # OUTPUT:«(a a)␤»
say <a b c a>.min(:kv); # OUTPUT:«(0 a 3 a)␤»
say <a b c a>.min(:p);  # OUTPUT:«(0 => a 3 => a)␤»

In Range§

See primary documentation in context for method min

method min(Range:D:)

Returns the start point of the range.

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

In Supply§

See primary documentation in context for method min

method min(Supply:D: &custom-routine-to-use = &infix:<cmp> --> Supply:D)

Creates a supply that only emits values from the given supply if they are smaller than any value seen before. In other words, from a continuously descending supply it will emit all the values. From a continuously ascending supply it will only emit the first value. The optional parameter specifies the comparator, just as with Any.min.

In Operators§

See primary documentation in context for infix min

Returns the smallest of the arguments, as determined by cmp semantics.

my $foo = 42;
$foo min= 0   # read as: $foo decreases to 0

Note: Before 2022.06, in the cases of ties &min would return the first argument with that value, whereas &[min] would return its RHS. After 2022.06, &[min] returns its LHS in the case of ties, and now both return the same value as dictated by their List associativity.

say min 0, False; # OUTPUT: «0␤»
say 0 min False;  # OUTPUT: «0␤»
say min False, 0; # OUTPUT: «False␤»
say False min 0;  # OUTPUT: «False␤»