module Colog.Pure
( PureLoggerT (..)
, runPureLogT
, PureLogger
, runPureLog
, logMessagePure
) where
import Data.Sequence ((|>))
import Colog.Core.Action (LogAction (..))
newtype PureLoggerT msg m a = PureLoggerT
{ runPureLoggerT :: StateT (Seq msg) m a
} deriving (Functor, Applicative, Monad, MonadTrans, MonadState (Seq msg))
runPureLogT :: Functor m => PureLoggerT msg m a -> m (a, [msg])
runPureLogT = fmap (second toList) . usingStateT mempty . runPureLoggerT
type PureLogger msg a = PureLoggerT msg Identity a
runPureLog :: PureLogger msg a -> (a, [msg])
runPureLog = runIdentity . runPureLogT
logMessagePure :: Monad m => LogAction (PureLoggerT msg m) msg
logMessagePure = LogAction $ \msg -> modify' (|> msg)