conduit 0.5.5 → 0.5.6
raw patch · 3 files changed
+39/−1 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Conduit.List: iterM :: Monad m => (a -> m ()) -> GInfConduit a m a
Files
- Data/Conduit/List.hs +12/−0
- conduit.cabal +1/−1
- test/main.hs +26/−0
Data/Conduit/List.hs view
@@ -40,6 +40,7 @@ , filter -- ** Monadic , mapM+ , iterM , mapMaybeM , concatMapM , concatMapAccumM@@ -244,6 +245,17 @@ -- Since 0.3.0 mapM :: Monad m => (a -> m b) -> GInfConduit a m b mapM f = awaitForever $ yield <=< lift . f++-- | Apply a monadic action on all values in a stream.+--+-- This @Conduit@ can be used to perform a monadic side-effect for every+-- value, whilst passing the value through the @Conduit@ as-is.+--+-- > iterM f = mapM (\a -> f a >>= \() -> return a)+--+-- Since 0.5.6+iterM :: Monad m => (a -> m ()) -> GInfConduit a m a+iterM f = awaitForever $ \a -> lift (f a) >> yield a -- | Apply a transformation that may fail to all values in a stream, discarding -- the failures.
conduit.cabal view
@@ -1,5 +1,5 @@ Name: conduit-Version: 0.5.5+Version: 0.5.6 Synopsis: Streaming data processing library. Description: @conduit@ is a solution to the streaming data problem, allowing for production, transformation, and consumption of streams of data in constant memory. It is an alternative to lazy I\/O which guarantees deterministic resource handling, and fits in the same general solution space as @enumerator@/@iteratee@ and @pipes@. For a brief tutorial, please see the "Data.Conduit" module.
test/main.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE CPP #-} import Test.Hspec import Test.Hspec.QuickCheck (prop)+import Test.QuickCheck.Monadic (assert, monadicIO, run) import qualified Data.Conduit as C import qualified Data.Conduit.Util as C@@ -33,6 +34,7 @@ import Data.Functor.Identity (runIdentity) import Control.Monad (forever) import Data.Void (Void)+import qualified Control.Concurrent.MVar as M (@=?) :: (Eq a, Show a) => a -> a -> IO () (@=?) = flip shouldBe@@ -827,6 +829,30 @@ case x of Left _ -> return () Right t -> error $ "This should have failed: " ++ show t+ describe "iterM" $ do+ prop "behavior" $ \l -> monadicIO $ do+ let counter ref = CL.iterM (const $ liftIO $ M.modifyMVar_ ref (\i -> return $! i + 1))+ v <- run $ do+ ref <- M.newMVar 0+ CL.sourceList l C.$= counter ref C.$$ CL.mapM_ (const $ return ())+ M.readMVar ref++ assert $ v == length (l :: [Int])+ prop "mapM_ equivalence" $ \l -> monadicIO $ do+ let runTest h = run $ do+ ref <- M.newMVar (0 :: Int)+ let f = action ref+ s <- CL.sourceList (l :: [Int]) C.$= h f C.$$ CL.fold (+) 0+ c <- M.readMVar ref++ return (c, s)++ action ref = const $ liftIO $ M.modifyMVar_ ref (\i -> return $! i + 1)+ (c1, s1) <- runTest CL.iterM+ (c2, s2) <- runTest (\f -> CL.mapM (\a -> f a >>= \() -> return a))++ assert $ c1 == c2+ assert $ s1 == s2 it' :: String -> IO () -> Spec it' = it