Control.Monad.Journal.Class

monad-journal-0.7.2: Pure logger typeclass and monad transformer

Copyright | (C) Dimitri Sabadie
License | BSD3
Maintainer | dimitri.sabadie@gmail.com
Stability | stable
Portability | portable
Safe Haskell | Safe
Language | Haskell2010

Control.Monad.Journal.Class

Contents

- MonadJournal

Description

`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.

Synopsis

- 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 #

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`.

Minimal complete definition

journal, history, clear

Methods

journal :: w -> m () #

Log something.

history :: m w #

Extract the logs history.

clear :: m () #

Clear the logs history.

Instances

(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (MaybeT m) # |
Methods journal :: w -> MaybeT m () # history :: MaybeT m w # clear :: MaybeT m () #
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (ListT m) # |
Methods journal :: w -> ListT m () # history :: ListT m w # clear :: ListT m () #
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (EitherT e m) # |
Methods journal :: w -> EitherT e m () # history :: EitherT e m w # clear :: EitherT e m () #
(Monad m, Monoid w, Monoid q, MonadJournal w m) => MonadJournal w (WriterT q m) # |
Methods journal :: w -> WriterT q m () # history :: WriterT q m w # clear :: WriterT q m () #
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (StateT s m) # |
Methods journal :: w -> StateT s m () # history :: StateT s m w # clear :: StateT s m () #
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (IdentityT * m) # |
Methods journal :: w -> IdentityT * m () # history :: IdentityT * m w # clear :: IdentityT * m () #
(Monoid w, Monad m) => MonadJournal w (JournalT w m) # |
Methods journal :: w -> JournalT w m () # history :: JournalT w m w # clear :: JournalT w m () #
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (ReaderT * r m) # |
Methods journal :: w -> ReaderT * r m () # history :: ReaderT * r m w # clear :: ReaderT * r m () #
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (RWST r w s m) # |
Methods journal :: w -> RWST r w s m () # history :: RWST r w s m w # clear :: RWST r w s m () #

sink :: (MonadJournal w m, MonadIO m) => (w -> IO ()) -> m () #

Sink all logs history through `MonadIO` then clean it.

absorb :: MonadJournal w m => (a, w) -> m a #

Absorb a logs history and pass around the value.