max package:numhask

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 42
>>> sconcat $ Max 1 :| [ Max n | n <- [2 .. 100]]
Max {getMax = 100}
The largest element of a non-empty structure. 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.

Examples

Basic usage:
>>> maximumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"]
"Longest"
WARNING: This function is partial for possibly-empty structures like lists.

Examples

>>> Max (Arg 0 ()) <> Max (Arg 1 ())
Max {getMax = Arg 1 ()}
>>> maximum [ Arg (length name) name | name <- ["violencia", "lea", "pixie"]]
Arg 9 "violencia"