{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RankNTypes #-}
module Orville.PostgreSQL.Monad.HasOrvilleState
( HasOrvilleState (askOrvilleState, localOrvilleState)
)
where
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Reader (ReaderT, ask, local, mapReaderT)
import Orville.PostgreSQL.OrvilleState (OrvilleState)
class HasOrvilleState m where
askOrvilleState :: m OrvilleState
localOrvilleState ::
(OrvilleState -> OrvilleState) ->
m a ->
m a
instance Monad m => HasOrvilleState (ReaderT OrvilleState m) where
askOrvilleState :: ReaderT OrvilleState m OrvilleState
askOrvilleState = ReaderT OrvilleState m OrvilleState
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
localOrvilleState :: forall a.
(OrvilleState -> OrvilleState)
-> ReaderT OrvilleState m a -> ReaderT OrvilleState m a
localOrvilleState = (OrvilleState -> OrvilleState)
-> ReaderT OrvilleState m a -> ReaderT OrvilleState m a
forall r (m :: * -> *) a.
(r -> r) -> ReaderT r m a -> ReaderT r m a
local
instance {-# OVERLAPS #-} (Monad m, HasOrvilleState m) => HasOrvilleState (ReaderT r m) where
askOrvilleState :: ReaderT r m OrvilleState
askOrvilleState = m OrvilleState -> ReaderT r m OrvilleState
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m OrvilleState
forall (m :: * -> *). HasOrvilleState m => m OrvilleState
askOrvilleState
localOrvilleState :: forall a.
(OrvilleState -> OrvilleState) -> ReaderT r m a -> ReaderT r m a
localOrvilleState OrvilleState -> OrvilleState
f = (m a -> m a) -> ReaderT r m a -> ReaderT r m a
forall (m :: * -> *) a (n :: * -> *) b r.
(m a -> n b) -> ReaderT r m a -> ReaderT r n b
mapReaderT ((OrvilleState -> OrvilleState) -> m a -> m a
forall a. (OrvilleState -> OrvilleState) -> m a -> m a
forall (m :: * -> *) a.
HasOrvilleState m =>
(OrvilleState -> OrvilleState) -> m a -> m a
localOrvilleState OrvilleState -> OrvilleState
f)