{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE TypeFamilies #-}

module Data.Monoid.LastMin where

import qualified Data.Vector.Generic as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed as U

newtype LastMin a = LastMin a
  deriving (LastMin a -> LastMin a -> Bool
(LastMin a -> LastMin a -> Bool)
-> (LastMin a -> LastMin a -> Bool) -> Eq (LastMin a)
forall a. Eq a => LastMin a -> LastMin a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => LastMin a -> LastMin a -> Bool
== :: LastMin a -> LastMin a -> Bool
$c/= :: forall a. Eq a => LastMin a -> LastMin a -> Bool
/= :: LastMin a -> LastMin a -> Bool
Eq, Int -> LastMin a -> ShowS
[LastMin a] -> ShowS
LastMin a -> String
(Int -> LastMin a -> ShowS)
-> (LastMin a -> String)
-> ([LastMin a] -> ShowS)
-> Show (LastMin a)
forall a. Show a => Int -> LastMin a -> ShowS
forall a. Show a => [LastMin a] -> ShowS
forall a. Show a => LastMin a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> LastMin a -> ShowS
showsPrec :: Int -> LastMin a -> ShowS
$cshow :: forall a. Show a => LastMin a -> String
show :: LastMin a -> String
$cshowList :: forall a. Show a => [LastMin a] -> ShowS
showList :: [LastMin a] -> ShowS
Show, LastMin a
LastMin a -> LastMin a -> Bounded (LastMin a)
forall a. a -> a -> Bounded a
forall a. Bounded a => LastMin a
$cminBound :: forall a. Bounded a => LastMin a
minBound :: LastMin a
$cmaxBound :: forall a. Bounded a => LastMin a
maxBound :: LastMin a
Bounded)

instance (Eq a, Bounded a) => Semigroup (LastMin a) where
  LastMin a
x <> :: LastMin a -> LastMin a -> LastMin a
<> LastMin a
y
    | LastMin a
y LastMin a -> LastMin a -> Bool
forall a. Eq a => a -> a -> Bool
== LastMin a
forall a. Bounded a => a
maxBound = LastMin a
x
    | Bool
otherwise = LastMin a
y

instance (Eq a, Bounded a) => Monoid (LastMin a) where
  mempty :: LastMin a
mempty = LastMin a
forall a. Bounded a => a
maxBound
  mconcat :: [LastMin a] -> LastMin a
mconcat = [LastMin a] -> LastMin a
forall a. HasCallStack => [a] -> a
last ([LastMin a] -> LastMin a)
-> ([LastMin a] -> [LastMin a]) -> [LastMin a] -> LastMin a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LastMin a
forall a. Monoid a => a
mempty :)

newtype instance U.MVector s (LastMin a) = MV_LastMin (U.MVector s a)
newtype instance U.Vector (LastMin a) = V_LastMin (U.Vector a)
deriving newtype instance (U.Unbox a) => GM.MVector U.MVector (LastMin a)
deriving newtype instance (U.Unbox a) => G.Vector U.Vector (LastMin a)
instance (U.Unbox a) => U.Unbox (LastMin a)