Control.Monad.Journal.Class

monad-journal-0.7.1: 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
  - journal :: w -> m ()
  - history :: m w
  - clear :: m ()
- 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`.

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) |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (ListT m) |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (IdentityT m) |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (EitherT e m) |
(Monad m, Monoid w, Monoid q, MonadJournal w m) => MonadJournal w (WriterT q m) |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (StateT s m) |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (ReaderT r m) |
(Monoid w, Monad m) => MonadJournal w (JournalT w m) |
(Monad m, Monoid w, MonadJournal w m) => MonadJournal w (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.