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

module Data.Monoid.LastMax where

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

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

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

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

newtype instance U.MVector s (LastMax a) = MV_LastMax (U.MVector s a)
newtype instance U.Vector (LastMax a) = V_LastMax (U.Vector a)
deriving newtype instance (U.Unbox a) => GM.MVector U.MVector (LastMax a)
deriving newtype instance (U.Unbox a) => G.Vector U.Vector (LastMax a)
instance (U.Unbox a) => U.Unbox (LastMax a)