Created
April 29, 2022 21:37
-
-
Save carymrobbins/ea549b4df313a7b736e378879a1fe319 to your computer and use it in GitHub Desktop.
Revisions
-
carymrobbins created this gist
Apr 29, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ module ContextLifted where import Control.Monad.Catch (MonadMask) import Control.Monad.IO.Class import qualified Context import qualified Context.Internal import qualified Control.Monad.Catch as Monad.Catch adjust :: (MonadIO m, MonadMask m) => Context.Store ctx -> (ctx -> ctx) -> m a -> m a adjust store f action = do adjustedContext <- liftIO $ Context.mines store f use store adjustedContext action use :: (MonadIO m, MonadMask m) => Context.Store ctx -> ctx -> m a -> m a use store context = Monad.Catch.bracket_ (liftIO $ Context.Internal.push store context) (liftIO $ Context.Internal.pop store)