subG-0.2.1.0: Some extension to the Foldable and Monoid classes.
Copyright(c) OleksandrZhabenko 2020
LicenseMIT
Maintainerolexandr543@yahoo.com
StabilityExperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.MinMax

Description

Functions to find both minimum and maximum elements of the Foldable structure of the Ordered elements.

Synopsis

Documentation

minmaxP :: Ord a => a -> a -> (a, a) Source #

Returns a pair where the first element is the minimum element from the two given ones and the second one is the maximum. If the arguments are equal then the tuple contains equal elements.

betweenNX :: Ord a => a -> a -> a -> Bool Source #

A ternary predicate to check whether the third argument lies between the first two unequal ones or whether they are all equal.

minMax :: (Ord a, Foldable t) => t a -> Maybe (a, a) Source #

Finds out the minimum and maximum values of the finite structure. If the latter one is empty returns Nothing, if all the elements are equal (or it has just one) then it returns Just tuple of equal elements.

minMaxBy :: (Ord a, Foldable t) => (a -> a -> Ordering) -> t a -> Maybe (a, a) Source #

A generalized variant of the minMax where you can specify your own comparison function.

minMax21 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe ((a, a), a) Source #

Given a finite structure with at least 3 elements returns a tuple with the two most minimum elements (the first one is less than the second one) and the maximum element. If the structure has less elements, returns Nothing. Uses just three passes through the structure, so may be more efficient than some other approaches.

minMax12 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe (a, (a, a)) Source #

Given a finite structure with at least 3 elements returns a tuple with the minimum element and two maximum elements (the first one is less than the second one). If the structure has less elements, returns Nothing. Uses just three passes through the structure, so may be more efficient than some other approaches.

minMax22 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe ((a, a), (a, a)) Source #

Given a finite structure with at least 4 elements returns a tuple with two minimum elements and two maximum elements. If the structure has less elements, returns Nothing. Uses just three passes through the structure, so may be more efficient than some other approaches.