subG-0.6.1.0: Some extension to the Foldable and Monoid classes.
Copyright(c) OleksandrZhabenko 2020-2023
LicenseMIT
Maintaineroleksandr.zhabenko@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.

minmaxPBy :: Ord a => (a -> a -> Ordering) -> a -> a -> (a, a) Source #

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

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.

betweenNXBy :: Ord a => (a -> a -> Ordering) -> a -> a -> a -> Bool Source #

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

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

Finds out the minimum and maximum values of the finite structure that has not less than two elements. Otherwise returns Nothing.

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

A generalized variant of the minMax11 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.

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

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

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.

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

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

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.

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

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