packages feed

unliftio-core 0.1.1.0 → 0.1.2.0

raw patch · 3 files changed

+39/−8 lines, 3 filesdep ~base

Dependency ranges changed: base

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.1.2.0++* Add `wrappedWithRunInIO`.+ ## 0.1.1.0  * Doc improvements.
src/Control/Monad/IO/Unlift.hs view
@@ -7,10 +7,10 @@   , askRunInIO   , withUnliftIO   , toIO+  , wrappedWithRunInIO   , MonadIO (..)   ) where -import Control.Monad (liftM) import Control.Monad.IO.Class import Control.Monad.Trans.Reader (ReaderT (..)) import Control.Monad.Trans.Identity (IdentityT (..))@@ -57,6 +57,7 @@   --   -- See 'UnliftIO' for an explanation of why we need a helper   -- datatype here.+  --   -- @since 0.1.0.0   askUnliftIO :: m (UnliftIO m)   askUnliftIO = withRunInIO (\run -> return (UnliftIO run))@@ -99,7 +100,7 @@     withRunInIO $ \run ->     inner (run . runIdentityT) --- | Same ask 'askUnliftIO', but returns a monomorphic function+-- | Same as 'askUnliftIO', but returns a monomorphic function -- instead of a polymorphic newtype wrapper. If you only need to apply -- the transformation on one concrete type, this function can be more -- convenient.@@ -125,3 +126,29 @@ {-# INLINE toIO #-} toIO :: MonadUnliftIO m => m a -> m (IO a) toIO m = withRunInIO $ \run -> return $ run m++{- | A helper function for implementing @MonadUnliftIO@ instances.+Useful for the common case where you want to simply delegate to the+underlying transformer.++@since 0.1.2.0+==== __Example__++> newtype AppT m a = AppT { unAppT :: ReaderT Int (ResourceT m) a }+>   deriving (Functor, Applicative, Monad, MonadIO)+>   -- Unfortunately, deriving MonadUnliftIO does not work.+>+> instance MonadUnliftIO m => MonadUnliftIO (AppT m) where+>   withRunInIO = wrappedWithRunInIO AppT unAppT+-}+{-# INLINE wrappedWithRunInIO #-}+wrappedWithRunInIO :: MonadUnliftIO n+                   => (n b -> m b)+                   -- ^ The wrapper, for instance @IdentityT@.+                   -> (forall a. m a -> n a)+                   -- ^ The inverse, for instance @runIdentityT@.+                   -> ((forall a. m a -> IO a) -> IO b)+                   -- ^ The actual function to invoke 'withRunInIO' with.+                   -> m b+wrappedWithRunInIO wrap unwrap inner = wrap $ withRunInIO $ \run ->+  inner $ run . unwrap
unliftio-core.cabal view
@@ -1,11 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.21.2.+cabal-version: >= 1.10++-- This file has been generated from package.yaml by hpack version 0.29.6. -- -- see: https://github.com/sol/hpack ----- hash: 30994f07a9010e7816784501ed5ff3165c34026fa5dc555ebf1a70f6d6c0f1af+-- hash: 9dda29b2ae88c7aba738c44b9efa373de55a416be845a7bf888fc8c108166fed  name:           unliftio-core-version:        0.1.1.0+version:        0.1.2.0 synopsis:       The MonadUnliftIO typeclass for unlifting monads to IO description:    Please see the documentation and README at <https://www.stackage.org/package/unliftio-core> category:       Control@@ -16,8 +18,6 @@ license:        MIT license-file:   LICENSE build-type:     Simple-cabal-version:  >= 1.10- extra-source-files:     ChangeLog.md     README.md@@ -26,7 +26,7 @@   hs-source-dirs:       src   build-depends:-      base >=4.5 && <4.11+      base >=4.5 && <4.12     , transformers >=0.2 && <0.6   exposed-modules:       Control.Monad.IO.Unlift