Maximum

Syntax

	max($num1, ..., $numN)

$set.max()

Description

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

The maximum 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 larger 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 maximum. One of them must be defined.
set Set A set of numbers to compare with each other to find the maximum.

Return Value

Type: Number

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

Examples

Simple number comparison

	max(1, 8, 3, 10)

Output: 10

Number comparison with a list

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

Output: 10

Number comparison with double numbers

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

Output: 10

Number comparison with null

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

Output: 10

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: d

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