Copyright | Flipstone Technology Partners 2023 |
---|---|
License | MIT |
Stability | Stable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Since: 1.0.0.0
Synopsis
- class HasOrvilleState m where
- askOrvilleState :: m OrvilleState
- localOrvilleState :: (OrvilleState -> OrvilleState) -> m a -> m a
Documentation
class HasOrvilleState m where Source #
HasOrvilleState
is the typeclass that Orville uses to access and manange
the connection pool and state tracking when it is being executed inside an
unknown Monad. It is a specialized version of the Reader interface so that it
can be easily implemented by application Monads that already have a Reader
context and want to simply add OrvilleState
as an attribute to that
context, like so
data MyApplicationState = MyApplicationState { appConfig :: MyAppConfig , appOrvilleState :: OrvilleState } newtype MyApplicationMonad a = MyApplicationMonad (ReaderT MyApplicationState IO) a instance HasOrvilleState MyApplicationMonad where askOrvilleState = MyApplicationMonad (asks appOrvilleState) localOrvilleState f (MyApplicationMonad reader) = MyApplicationMonad $ local (\state -> state { appOrvilleState = f (appOrvilleState state)) reader
An instance for 'ReaderT OrvilleState m' is provided as a convenience in the case that your application has no extra context to track.
Since: 1.0.0.0
askOrvilleState :: m OrvilleState Source #
Fetches the current OrvilleState
from the host Monad context. The
equivalent of ask
for 'ReaderT OrvilleState'.
Since: 1.0.0.0
:: (OrvilleState -> OrvilleState) | The function to modify the |
-> m a | The monad operation to execute with the modified state. |
-> m a |
Applies a modification to the OrvilleState
that is local to the given
monad operation. Calls to askOrvilleState
made within the 'm a' provided
must return the modified state. The modified state must only apply to
the given 'm a' and not be persisted beyond it. The equivalent of local
for 'ReaderT OrvilleState'.
Since: 1.0.0.0
Instances
HasOrvilleState Orville Source # | |
Defined in Orville.PostgreSQL.Monad.Orville askOrvilleState :: Orville OrvilleState Source # localOrvilleState :: (OrvilleState -> OrvilleState) -> Orville a -> Orville a Source # | |
Monad m => HasOrvilleState (ReaderT OrvilleState m) Source # | |
Defined in Orville.PostgreSQL.Monad.HasOrvilleState askOrvilleState :: ReaderT OrvilleState m OrvilleState Source # localOrvilleState :: (OrvilleState -> OrvilleState) -> ReaderT OrvilleState m a -> ReaderT OrvilleState m a Source # | |
(Monad m, HasOrvilleState m) => HasOrvilleState (ReaderT r m) Source # | |
Defined in Orville.PostgreSQL.Monad.HasOrvilleState askOrvilleState :: ReaderT r m OrvilleState Source # localOrvilleState :: (OrvilleState -> OrvilleState) -> ReaderT r m a -> ReaderT r m a Source # |