File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,8 @@ import Control.Monad.Trans.RWS.Strict as Strict
2929import Control.Monad.Trans.Writer.Lazy as Lazy
3030import Control.Monad.Trans.Writer.Strict as Strict
3131import Data.Functor.Identity
32+ import Data.Functor.Compose
33+ import Data.Tuple (swap )
3234
3335-- | A declare monad transformer parametrized by:
3436--
@@ -115,6 +117,14 @@ execDeclareT (DeclareT f) d = fst <$> f d
115117undeclareT :: (Monad m , Monoid d ) => DeclareT d m a -> m a
116118undeclareT = flip evalDeclareT mempty
117119
120+ -- | Lift a declaration-producing computation for a subpart into a
121+ -- declaration-producing computation for the whole.
122+ hoistDeclareT :: Functor m => Lens' d d' -> DeclareT d' m a -> DeclareT d m a
123+ hoistDeclareT l = DeclareT . unconvert . l . convert . runDeclareT
124+ where
125+ convert f = Compose . fmap swap . f
126+ unconvert f = fmap swap . getCompose . f
127+
118128-- | A declare monad parametrized by @d@ — the output to accumulate (declarations).
119129--
120130-- This monad is similar to both state and writer monads.
You can’t perform that action at this time.
0 commit comments