max package:base

The Max Monoid and Semigroup always choose the bigger element as by the Ord instance and max of the contained type.

Examples

>>> Max 42 <> Max 3
Max {getMax = 42}
>>> sconcat $ Max 1 :| [ Max n | n <- [2 .. 100]]
Max {getMax = 100}
Maximum between two comparable types.
The largest element of a non-empty structure. This function is equivalent to foldr1 max, and its behavior on structures with multiple largest elements depends on the relevant implementation of max. For the default implementation of max (max x y = if x <= y then y else x), structure order is used as a tie-breaker: if there are multiple largest elements, the rightmost of them is chosen (this is equivalent to maximumBy compare). This function is non-total and will raise a runtime exception if the structure happens to be empty. A structure that supports random access and maintains its elements in order should provide a specialised implementation to return the maximum in faster than linear time.

Examples

Basic usage:
>>> maximum [1..10]
10
>>> maximum []
*** Exception: Prelude.maximum: empty list
>>> maximum Nothing
*** Exception: maximum: empty structure
WARNING: This function is partial for possibly-empty structures like lists.
The largest element of a non-empty structure with respect to the given comparison function. Structure order is used as a tie-breaker: if there are multiple largest elements, the rightmost of them is chosen.

Examples

Basic usage:
>>> maximumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"]
"Longest"
WARNING: This function is partial for possibly-empty structures like lists.
Gets the maximum constructor index of an algebraic datatype
The largest element of a non-empty structure. This function is equivalent to foldr1 max, and its behavior on structures with multiple largest elements depends on the relevant implementation of max. For the default implementation of max (max x y = if x <= y then y else x), structure order is used as a tie-breaker: if there are multiple largest elements, the rightmost of them is chosen (this is equivalent to maximumBy compare).
>>> maximum (32 :| [64, 8, 128, 16])
128
The largest element of a non-empty structure with respect to the given comparison function. Structure order is used as a tie-breaker: if there are multiple largest elements, the rightmost of them is chosen.
maximum returns the maximum value from a list, which must be non-empty, finite, and of an ordered type. This function is equivalent to foldr1 max, and its behavior on lists with multiple maxima depends on the relevant implementation of max. For the default implementation of max, list order is used as a tie-breaker: if there are multiple maxima, the rightmost of them is chosen (this is equivalent to maximumBy compare).
>>> maximum []
*** Exception: Prelude.maximum: empty list

>>> maximum [42]
42

>>> maximum [55, -12, 7, 0, -89]
55

>>> maximum [1..]
* Hangs forever *
Maximum live data in compact regions
Maximum live data in large objects
Maximum live data (including large objects + compact regions) in the heap. Updated after a major GC.
Maximum memory in use by the RTS
Maximum slop
The largest element of a non-empty structure. This function is equivalent to bifoldr1 max, and its behavior on structures with multiple largest elements depends on the relevant implementation of max. For the default implementation of max (max x y = if x <= y then y else x), structure order is used as a tie-breaker: if there are multiple largest elements, the rightmost of them is chosen (this is equivalent to bimaximumBy compare).

Examples

Basic usage:
>>> bimaximum (42, 17)
42
>>> bimaximum (Right 42)
42
>>> bimaximum (BiList [13, 29, 4] [18, 1, 7])
29
>>> bimaximum (BiList [13, 29, 4] [])
29
On empty structures, this function throws an exception:
>>> bimaximum (BiList [] [])
*** Exception: bimaximum: empty structure
...