module Data.RangeMin.Internal.HandyOrdering(Comparator, orderPairBy,
orderPair, minBy, maxBy, maximumBy, minimumBy, comparing) where
import Data.List(maximumBy, minimumBy)
import Data.RangeMin.Internal.Combinators(on)
type Comparator e = e -> e -> Ordering
comparing :: Ord b => (a -> b) -> Comparator a
comparing f = compare `on` f
orderPairBy :: Comparator e -> (e, e) -> (e, e)
orderPairBy cmp (x,y) = if cmp x y == GT then (y,x) else (x,y)
orderPair :: Ord e => (e, e) -> (e, e)
orderPair (x,y) = if x <= y then (x, y) else (y, x)
minBy :: Comparator e -> e -> e -> e
minBy cmp x y = if cmp x y == GT then y else x
maxBy :: Comparator e -> e -> e -> e
maxBy = minBy . flip