File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed
co-log-core/src/Colog/Core Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change 1
- {-# LANGUAGE CPP #-}
1
+ {-# LANGUAGE CPP #-}
2
+ {-# LANGUAGE Rank2Types #-}
2
3
3
4
{- |
4
5
Copyright: (c) 2018-2019 Kowainik
@@ -48,6 +49,9 @@ module Colog.Core.Action
48
49
, (<<=)
49
50
, duplicate
50
51
, multiplicate
52
+
53
+ -- * Higher-order combinators
54
+ , hoistLogAction
51
55
) where
52
56
53
57
import Control.Monad (when , (>=>) )
@@ -575,3 +579,28 @@ multiplicate (LogAction l) = LogAction $ \msgs -> l (fold msgs)
575
579
{-# INLINE multiplicate #-}
576
580
{-# SPECIALIZE multiplicate :: Monoid msg => LogAction m msg -> LogAction m [msg] #-}
577
581
{-# SPECIALIZE multiplicate :: Monoid msg => LogAction m msg -> LogAction m (NonEmpty msg) #-}
582
+
583
+ {- | Allows changing the internal monadic action.
584
+
585
+ Let's say we have a pure logger action using 'PureLogger'
586
+ and we want to log all messages into 'IO' instead.
587
+
588
+ If we provide the following function:
589
+
590
+ @
591
+ performPureLogsInIO :: PureLogger a -> IO a
592
+ @
593
+
594
+ then we can convert a logger action that uses a pure monad
595
+ to a one that performs the logging in the 'IO' monad using:
596
+
597
+ @
598
+ hoistLogAction performPureLogsInIO :: LogAction (PureLogger a) a -> LogAction IO a
599
+ @
600
+ -}
601
+ hoistLogAction
602
+ :: (forall x . m x -> n x )
603
+ -> LogAction m a
604
+ -> LogAction n a
605
+ hoistLogAction f (LogAction l) = LogAction (f . l)
606
+ {-# INLINE hoistLogAction #-}
You can’t perform that action at this time.
0 commit comments