Minimum

Syntax

	min($num1, ..., $numN)

$set.min()

Description

Calculates the minimum of the given numbers. The function can be called with either multiple arguments or a set or list of numbers as arguments. null values are filtered out and have no influence on the result.

The minimum with respect to a user-defined comparison function can be calculated via Reduction:

cmp -> list -> 
  $list.reduce(null, 
    x -> y -> 
      if ($x == null, $y, 
        if ($cmp($x, $y) < 0, $y, $x)))

The function defined in this way expects a Comparison function as first argument and a list as second argument. It reduces the list to the single element which is smaller than any other element compared by the comparator function.

Parameters

Name Type Description Mandatory Default
num Number A number to be compared with the other specified numbers to determine the minimum. One of them must be defined.
set Set A set of numbers to compare with each other to find the minimum.

Return Value

Type: Number

The number from the given set of numbers that is lowest.

Examples

Simple number comparison

	min(1, 8, 3, 10)

Output: 1

Number comparison with a list

	list(1, 8, 3, 10).min()

Output: 1

Number comparison with double numbers

	list(1, 8, 10, 8, 3, 10).min()

Output: 1

Number comparison with null

	list(1, null, null, 8, 3, 10).max()

Output: 1

null values are ignored in the comparison

Comparison with a user defined function for strings

{
   cmpFun = a -> b -> if($a > $b, -1, 1);
   (cmp -> list -> 
      $list.reduce("", 
         x -> y -> 
            if ($x == null, $y, 
               if ($cmp($x, $y) < 0, $y, $x)
           )
      )
   ).apply($cmpFun, list("c", "b", "d", "a"));
}

Output: a

The min() function cannot handle strings, for this a custom function must be defined for a minimum determination for strings.