packages feed

streaming-with 0.2.0.0 → 0.2.1.0

raw patch · 4 files changed

+72/−7 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Streaming.With.Lifted: class (Withable w) => RunWithable w
+ Streaming.With.Lifted: instance (Control.Monad.Catch.MonadMask m, Control.Monad.IO.Class.MonadIO m) => Streaming.With.Lifted.RunWithable (Control.Monad.Trans.Cont.ContT () m)
+ Streaming.With.Lifted: instance Streaming.With.Lifted.RunWithable Control.Monad.Managed.Managed
+ Streaming.With.Lifted: liftActionIO :: (Withable w) => IO a -> w a
+ Streaming.With.Lifted: runWith :: RunWithable w => w () -> WithMonad w ()
+ Streaming.With.Lifted: within :: (Withable w) => w a -> (a -> WithMonad w b) -> w b
- Streaming.With.Lifted: class (Monad w, MonadMask (WithMonad w), MonadIO (WithMonad w)) => Withable w where type WithMonad w :: * -> * where {
+ Streaming.With.Lifted: class (Monad w, MonadMask (WithMonad w), MonadIO (WithMonad w)) => Withable w where {

Files

ChangeLog.md view
@@ -1,5 +1,12 @@ # Revision history for streaming-with +## 0.2.1.0 -- 2018-02-06++* Add the `RunWithable` class.++* Add the `within`, `liftActionIO` and `liftThrow` functions for use+  with `Withable`.+ ## 0.2.0.0 -- 2017-07-07  * Add `Monad w` constraint to `Withable w`
README.md view
@@ -1,7 +1,7 @@ streaming-with ============== -[![Hackage](https://img.shields.io/hackage/v/streaming-with.svg)](https://hackage.haskell.org/package/streaming-with) [![Build Status](https://travis-ci.org/ivan-m/streaming-with.svg)](https://travis-ci.org/ivan-m/streaming-with)+[![Hackage](https://img.shields.io/hackage/v/streaming-with.svg)](https://hackage.haskell.org/package/streaming-with) [![Build Status](https://travis-ci.org/haskell-streaming/streaming-with.svg)](https://travis-ci.org/haskell-streaming/streaming-with)  > with/bracket-style idioms for use with [streaming] 
src/Streaming/With/Lifted.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE FlexibleContexts, RankNTypes, TypeFamilies #-}+{-# LANGUAGE FlexibleContexts, FlexibleInstances, RankNTypes, TypeFamilies #-}  {- |    Module      : Streaming.With.Lifted@@ -37,6 +37,9 @@  -} module Streaming.With.Lifted   ( Withable (..)+  , RunWithable (..)+  , within+  , liftActionIO     -- * File-handling   , withFile   , withBinaryFile@@ -58,11 +61,12 @@ import           Data.ByteString.Streaming (ByteString) import qualified Streaming.With            as W -import Control.Monad.Catch       (MonadMask, bracket)+import Control.Exception         (Exception)+import Control.Monad.Catch       (MonadMask, bracket, throwM) import Control.Monad.IO.Class    (MonadIO, liftIO)-import Control.Monad.Managed     (Managed, managed)+import Control.Monad.Managed     (Managed, managed, runManaged) import Control.Monad.Trans.Class (lift)-import Control.Monad.Trans.Cont  (ContT(..))+import Control.Monad.Trans.Cont  (ContT(..), runContT) import System.IO                 (Handle, IOMode)  --------------------------------------------------------------------------------@@ -98,6 +102,60 @@   liftWith = ContT    liftAction = lift++-- | Safely run the provided continuation.+--+--   A result of type '()' is required to ensure no resources are+--   leaked.+--+--   Note that you cannot write something like:+--+--   > copyBoth :: FilePath -> FilePath -> FilePath -> IO ()+--   > copyBoth inF1 inF2 outF = runWith $ do+--   >   bs1 <- withBinaryFileContents inF1+--   >   bs2 <- withBinaryFileContents inF2+--   >   writeBinaryFile outF bs1+--   >   appendBinaryFile outF bs2+--+--   as the 'RunWithable' instance cannot be inferred.  As such, you+--   will need to specify a type somewhere.+--+--   @since 0.2.1.0+class (Withable w) => RunWithable w where+  runWith :: w () -> WithMonad w ()++instance RunWithable Managed where+  runWith = runManaged++instance (MonadMask m, MonadIO m) => RunWithable (ContT () m) where+  runWith = flip runContT return++-- | A helper function to run a computation within a lifted resource+--   management expression.+--+--   @within w f = w >>= liftAction . f@+--+--   @since 0.2.1.0+within :: (Withable w) => w a -> (a -> WithMonad w b) -> w b+within w f = w >>= liftAction . f++-- | A helper function for the common case of lifting an @IO@+--   computation into a @Withable@.+--+--   @liftActionIO = liftAction . liftIO@.+--+--   @since 0.2.1.0+liftActionIO :: (Withable w) => IO a -> w a+liftActionIO = liftAction . liftIO++-- | A helper function for the common case of throwing an exception in+--   the underlying monad.+--+--   @liftThrow = liftAction . throwM@.+--+--   @since 0.2.1.0+liftThrow :: (Withable w, Exception e) => e -> w a+liftThrow = liftAction . throwM  -------------------------------------------------------------------------------- 
streaming-with.cabal view
@@ -1,5 +1,5 @@ name:                streaming-with-version:             0.2.0.0+version:             0.2.1.0 synopsis:            with/bracket-style idioms for use with streaming description:     This package provides the foundations for a continuation-based@@ -17,7 +17,7 @@  source-repository head   type:     git-  location: https://github.com/ivan-m/streaming-with.git+  location: https://github.com/haskell-streaming/streaming-with.git  library   exposed-modules:     Streaming.With