maximum
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.
>>> maximum (32 :| [64, 8, 128, 16])
128
maximum returns the maximum value from a list, which must be
non-empty, finite, and of an ordered type. It is a special case of
maximumBy, which allows the programmer to supply their own
comparison function.
>>> maximum []
*** Exception: Prelude.maximum: empty list
>>> maximum [42]
42
>>> maximum [55, -12, 7, 0, -89]
55
>>> maximum [1..]
* Hangs forever *
O(n) maximum returns the maximum value from a
ByteString An exception will be thrown in the case of an empty
ByteString.
O(n) maximum returns the maximum value from a
Text, which must be non-empty.
O(n) maximum returns the maximum value from a stream, which
must be non-empty.
Properties
maximum . stream = maximum
O(n) Yield the maximum element of the vector. The vector may
not be empty. In case of a tie, the first occurrence wins.
Examples
>>> import qualified Data.Vector as V
>>> V.maximum $ V.fromList [2, 1]
2
>>> import Data.Semigroup
>>> V.maximum $ V.fromList [Arg 1 'a', Arg 2 'b']
Arg 2 'b'
>>> V.maximum $ V.fromList [Arg 1 'a', Arg 1 'b']
Arg 1 'a'
O(n) Yield the maximum element of the vector. The vector may
not be empty. In case of a tie, the first occurrence wins.
Examples
>>> import qualified Data.Vector as V
>>> V.maximum $ V.fromList [2, 1]
2
>>> import Data.Semigroup
>>> V.maximum $ V.fromList [Arg 1 'a', Arg 2 'b']
Arg 2 'b'
>>> V.maximum $ V.fromList [Arg 1 'a', Arg 1 'b']
Arg 1 'a'
O(n) Yield the maximum element of the vector. The vector may
not be empty. In case of a tie, the first occurrence wins.
Examples
>>> import qualified Data.Vector.Primitive as VP
>>> VP.maximum $ VP.fromList [2, 1 :: Int]
2
O(n) Yield the maximum element of the vector. The vector may
not be empty. In case of a tie, the first occurrence wins.
Examples
>>> import qualified Data.Vector.Storable as VS
>>> VS.maximum $ VS.fromList [2, 1 :: Int]
2
O(n) Yield the maximum element of the vector. The vector may
not be empty. In case of a tie, the first occurrence wins.
Examples
>>> import qualified Data.Vector.Unboxed as VU
>>> VU.maximum $ VU.fromList [2, 1 :: Int]
2
>>> import Data.Semigroup
>>> VU.maximum $ VU.fromList [Arg 1 'a', Arg (2 :: Int) 'b']
Arg 2 'b'
>>> VU.maximum $ VU.fromList [Arg 1 'a', Arg (1 :: Int) 'b']
Arg 1 'a'
Get the largest value in the stream, if present.
Subject to fusion
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.
Computes the maximum element
Computes the maximum byte
Computes the maximum element
Computes the maximum character
maximum stream returns the greatest element in
stream or
Nothing if the stream is empty.
maximum consumes the entire stream.
ghci> is <- Streams.fromList [1, 2, 3]
ghci> Streams.maximum is
3
ghci> Streams.read is -- The stream is now empty
Nothing
O(n) maximum returns the maximum value from a
ByteString This function will fuse. An exception will be thrown
in the case of an empty ByteString.