about summary refs log tree commit diff
path: root/src/Xanthous/Util.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xanthous/Util.hs')
-rw-r--r--src/Xanthous/Util.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Xanthous/Util.hs b/src/Xanthous/Util.hs
index b8b789e1b1ea..93155af3fd59 100644
--- a/src/Xanthous/Util.hs
+++ b/src/Xanthous/Util.hs
@@ -26,6 +26,8 @@ module Xanthous.Util
   , takeWhileInclusive
   , smallestNotIn
   , removeVectorIndex
+  , maximum1
+  , minimum1
 
     -- * Type-level programming utils
   , KnownBool(..)
@@ -38,6 +40,8 @@ import           Data.Foldable (foldr)
 import           Data.Monoid
 import           Data.Proxy
 import qualified Data.Vector as V
+import           Data.Semigroup (Max(..), Min(..))
+import           Data.Semigroup.Foldable
 --------------------------------------------------------------------------------
 
 newtype EqEqProp a = EqEqProp a
@@ -218,6 +222,12 @@ removeVectorIndex idx vect =
   let (before, after) = V.splitAt idx vect
   in before <> fromMaybe Empty (tailMay after)
 
+maximum1 :: (Ord a, Foldable1 f) => f a -> a
+maximum1 = getMax . foldMap1 Max
+
+minimum1 :: (Ord a, Foldable1 f) => f a -> a
+minimum1 = getMin . foldMap1 Min
+
 --------------------------------------------------------------------------------
 
 -- | This class gives a boolean associated with a type-level bool, a'la