io-streams 1.3.5.0 → 1.3.6.0
raw patch · 4 files changed
+90/−3 lines, 4 filesdep ~vectorPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: vector
API changes (from Hackage documentation)
+ System.IO.Streams.Combinators: foldM_ :: (x -> a -> IO x) -> IO x -> (x -> IO s) -> InputStream a -> IO s
+ System.IO.Streams.Combinators: fold_ :: (x -> a -> x) -> x -> (x -> s) -> InputStream a -> IO s
- System.IO.Streams.Combinators: unzip :: InputStream (a, b) -> IO (InputStream a, InputStream b)
+ System.IO.Streams.Combinators: unzip :: forall a b. InputStream (a, b) -> IO (InputStream a, InputStream b)
Files
- changelog.md +15/−0
- io-streams.cabal +3/−3
- src/System/IO/Streams/Combinators.hs +57/−0
- test/System/IO/Streams/Tests/Combinators.hs +15/−0
changelog.md view
@@ -1,3 +1,18 @@+# Version 1.3.6.0+ - Added new fold functions:+ ```haskell+fold_ :: (x -> a -> x) -- ^ accumulator update function+ -> x -- ^ initial seed+ -> (x -> s) -- ^ recover folded value+ -> InputStream a -- ^ input stream+ -> IO s+foldM_ :: (x -> a -> IO x) -- ^ accumulator update action+ -> IO x -- ^ initial seed+ -> (x -> IO s) -- ^ recover folded value+ -> InputStream a -- ^ input stream+ -> IO s+ ```+ # Version 1.3.5.0 - Add support for latest `process`, `time`, and `transformers` releases (and thereby indirectly for the upcoming GHC 8.0).
io-streams.cabal view
@@ -1,5 +1,5 @@ Name: io-streams-Version: 1.3.5.0+Version: 1.3.6.0 License: BSD3 License-file: LICENSE Category: Data, Network, IO-Streams@@ -92,7 +92,7 @@ ghc-options: -Wall -fwarn-tabs -funbox-strict-fields -fno-warn-unused-do-bind - ghc-prof-options: -prof -auto-all+ ghc-prof-options: -auto-all Exposed-modules: System.IO.Streams, System.IO.Streams.Attoparsec,@@ -193,7 +193,7 @@ ghc-options: -Wall -fhpc -fwarn-tabs -funbox-strict-fields -threaded -fno-warn-unused-do-bind- ghc-prof-options: -prof -auto-all+ ghc-prof-options: -auto-all if !os(windows) && !flag(NoInteractiveTests) cpp-options: -DENABLE_PROCESS_TESTS
src/System/IO/Streams/Combinators.hs view
@@ -10,6 +10,8 @@ , outputFoldM , fold , foldM+ , fold_+ , foldM_ , any , all , maximum@@ -179,6 +181,61 @@ foldM f seed stream = go seed where go !s = read stream >>= maybe (return s) ((go =<<) . f s)+++------------------------------------------------------------------------------+-- | A variant of 'System.IO.Streams.fold' suitable for use with composable folds+-- from \'beautiful folding\' libraries like+-- <http://hackage.haskell.org/package/foldl the foldl library>.+-- The input stream is fully consumed. +--+-- Example:+--+-- @+-- ghci> let folds = liftA3 (,,) Foldl.length Foldl.mean Foldl.maximum+-- ghci> Streams.'System.IO.Streams.fromList' [1..10::Double] >>= Foldl.purely Streams.'System.IO.Streams.fold_' folds is+-- ghci> (10,5.5,Just 10.0)+-- @+--+-- /Since 1.3.6.0/+--+fold_ :: (x -> a -> x) -- ^ accumulator update function+ -> x -- ^ initial seed+ -> (x -> s) -- ^ recover folded value+ -> InputStream a -- ^ input stream+ -> IO s+fold_ op seed done stream = liftM done (go seed)+ where + go !s = read stream >>= maybe (return s) (go . op s)+++------------------------------------------------------------------------------+-- | A variant of 'System.IO.Streams.foldM' suitable for use with composable folds+-- from \'beautiful folding\' libraries like+-- <http://hackage.haskell.org/package/foldl the foldl library>.+-- The input stream is fully consumed. +--+-- Example:+--+-- @+-- ghci> let folds = Foldl.mapM_ print *> Foldl.generalize (liftA2 (,) Foldl.sum Foldl.mean)+-- ghci> Streams.'System.IO.Streams.fromList' [1..3::Double] >>= Foldl.impurely Streams.'System.IO.Streams.foldM_' folds+-- 1.0+-- 2.0+-- 3.0+-- (6.0,2.0)+-- @+--+-- /Since 1.3.6.0/+--+foldM_ :: (x -> a -> IO x) -- ^ accumulator update action+ -> IO x -- ^ initial seed+ -> (x -> IO s) -- ^ recover folded value+ -> InputStream a -- ^ input stream+ -> IO s+foldM_ f seed done stream = seed >>= go + where+ go !x = read stream >>= maybe (done x) ((go =<<) . f x) ------------------------------------------------------------------------------
test/System/IO/Streams/Tests/Combinators.hs view
@@ -40,6 +40,8 @@ , testFoldMWorksTwice , testFold , testFoldM+ , testFold_+ , testFoldM_ , testUnfoldM , testPredicates , testMap@@ -232,6 +234,19 @@ testFoldM = testCase "combinators/foldM" $ do fromList [1..10::Int] >>= S.foldM ((return .) . (+)) 0 >>= assertEqual "fold2" (sum [1..10])+++------------------------------------------------------------------------------+testFold_ :: Test+testFold_ = testCase "combinators/fold_" $ do+ fromList [1..10::Int] >>= S.fold_ (+) 0 id+ >>= assertEqual "fold_1" (sum [1..10])++------------------------------------------------------------------------------+testFoldM_ :: Test+testFoldM_ = testCase "combinators/foldM_" $ do+ fromList [1..10::Int] >>= S.foldM_ ((return .) . (+)) (return 0) return+ >>= assertEqual "fold_2" (sum [1..10]) ------------------------------------------------------------------------------