Last active
December 1, 2017 13:47
-
-
Save deque-blog/1a1d3af0112747e4fd0dbc551d07772f to your computer and use it in GitHub Desktop.
This file contains 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 characters
-- Wrapping a Reader Monad transformer (test environment) | |
newtype FakeCypher m a = FakeCypherT (ReaderT Cyphers m a) | |
deriving (Functor, Applicative, Monad, MonadTrans) | |
-- MonadCypher instance for our test environment | |
instance Monad m => MonadCypher (FakeCypher m) where | |
encryptJson json = do | |
cyphers <- FakeCypherT ask | |
pure (encryptMap cyphers M.! json) | |
decryptJson str = do | |
cyphers <- FakeCypherT ask | |
pure (M.lookup str (decryptMap cyphers)) | |
-- To run a `MonadCypher` computation in our test environment | |
runFakeCypher :: (Monad m) => FakeCypher m a -> Cyphers -> m a | |
runFakeCypher (FakeCypherT f) r = runReaderT f r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment