Copyright | (C) Dimitri Sabadie |
---|---|
License | BSD3 |
Maintainer | dimitri.sabadie@gmail.com |
Stability | stable |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
MonadWriter
on steroids.
MonadJournal
is a more controlable version of MonadWriter
because it
enables you to access the Monoid
being computed up. You can then access
logs inside the computation itself, whereas you cannot with
MonadWriter
– unless you use specific functions like listen
, but that
still stacks Monoid
in the monad.
Typically, you can use MonadJournal
when you come across the logging
problem and you need logs as long as you proceed.
- class (Monoid w, Monad m) => MonadJournal w m | m -> w where
- sink :: (MonadJournal w m, MonadIO m) => (w -> IO ()) -> m ()
- absorb :: MonadJournal w m => (a, w) -> m a
MonadJournal
class (Monoid w, Monad m) => MonadJournal w m | m -> w where Source
This typeclass provides the ability to accumulate Monoid
in a monad
via the journal
function; to get them via the history
function and
finally, to purge them all with the clear
function.
In most cases, you won’t need history
neither clear
. There’s a
cool function that combines both and enables you to deal with the
Monoid
: sink
.
Log something.
Extract the logs history.
Clear the logs history.
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (MaybeT m) Source | |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (ListT m) Source | |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (IdentityT m) Source | |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (EitherT e m) Source | |
(Monad m, Monoid w, Monoid q, MonadJournal w m) => MonadJournal w (WriterT q m) Source | |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (StateT s m) Source | |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (ReaderT r m) Source | |
(Monoid w, Monad m) => MonadJournal w (JournalT w m) Source | |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (RWST r w s m) Source |
sink :: (MonadJournal w m, MonadIO m) => (w -> IO ()) -> m () Source
Sink all logs history through MonadIO
then clean it.
absorb :: MonadJournal w m => (a, w) -> m a Source
Absorb a logs history and pass around the value.