Permalink
Browse files

Add 'transCas' to extract an IO action from a MonadCassandra context

  • Loading branch information...
1 parent 49dc793 commit b059bcf0e2272e87d19780f1671cd283bf5f9d04 @ozataman ozataman committed Jan 3, 2013
Showing with 15 additions and 0 deletions.
  1. +14 −0 src/Database/Cassandra/Basic.hs
  2. +1 −0 src/Database/Cassandra/JSON.hs
@@ -24,6 +24,7 @@ module Database.Cassandra.Basic
, MonadCassandra (..)
, Cas (..)
, runCas
+ , transCas
, mapCassandra
-- * Cassandra Operations
@@ -164,6 +165,19 @@ runCas :: CPool -> Cas a -> IO a
runCas = flip runReaderT
+-- | Unwrap a Cassandra action and return an IO continuation that can
+-- then be run in a pure IO context.
+--
+-- This is useful when you design all your functions in a generic form
+-- with 'MonadCassandra' m constraints and then one day need to feed
+-- your function to a utility that can only run in an IO context. This
+-- function is then your friendly utility for extracting an IO action.
+transCas :: MonadCassandra m => Cas a -> m (IO a)
+transCas m = do
+ cp <- getCassandraPool
+ return $ runCas cp m
+
+
-------------------------------------------------------------------------------
instance (MonadIO m) => MonadCassandra (ReaderT CPool m) where
getCassandraPool = ask
@@ -36,6 +36,7 @@ module Database.Cassandra.JSON
, MonadCassandra (..)
, Cas
, runCas
+ , transCas
, mapCassandra
-- * Cassandra Operations

0 comments on commit b059bcf

Please sign in to comment.