Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active December 1, 2017 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/1a1d3af0112747e4fd0dbc551d07772f to your computer and use it in GitHub Desktop.
Save deque-blog/1a1d3af0112747e4fd0dbc551d07772f to your computer and use it in GitHub Desktop.
-- 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