packages feed

pipes-transduce 0.3.0.1 → 0.3.1.0

raw patch · 5 files changed

+59/−21 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG view
@@ -1,10 +1,20 @@+0.3.1.0+=======++- Solved bug in "combined, added a test.+ 0.3.0.0+=======+ - Dropped unneeded deps.  0.2.3.0+=======+ - More efficient Applicative for Fold2  0.2.0.0+=======  - Added folds of two Producers. - Name changes.
README.md view
@@ -1,4 +1,4 @@-## Whats in this library?+## What's in this library?  A pair of fold-like datatypes that consume [Producers](http://hackage.haskell.org/package/pipes-4.1.7/docs/Pipes.html#t:Producer)@@ -11,15 +11,14 @@  ## Why was this library created? -I wanted a fold-like datatype for IO-based Producers that let me perform-"bracketing" operations (the folds in foldl are push-based and do not allow-that). +I wanted a fold-like datatype for Producers that allowed "bracketing"+operations like "withFile". -I also wanted to be able to fold two Producers concurrently (for example, take-the piped stdout & stderr streams of an external process and merge the lines-into a single file as they are produced).+I also wanted to be able to fold two Producers concurrently (for example, merge+the piped stdout & stderr streams of an external process into one unified+stream). -Finally, I wanted the fold-like datatype to have a "failure value" baked in.+Finally, I wanted the fold-like datatype to have a "failure option" baked in.  If you don't need any of that, you are better off using **pipes** and/or **foldl** by themselves. 
pipes-transduce.cabal view
@@ -1,5 +1,5 @@ Name: pipes-transduce-Version: 0.3.0.1+Version: 0.3.1.0 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3
src/Pipes/Transduce.hs view
@@ -528,9 +528,9 @@   {-| -    A computation in 'IO' that consumes concurrently (and completely drains)-    two 'Producer's of @b@ values, returning a value of type @a@, except when it-    fails early with an error of type @e@.+    A computation in 'IO' that completely drains two 'Producer's of @b@ values+    in a concurrent way, returning a value of type @a@, except when it fails early+    with an error of type @e@. -} newtype Fold2 b1 b2 e a = Fold2 (Lift (Fold2_ b1 b2 e) a) deriving (Functor) @@ -637,28 +637,33 @@         Conceit (exhaustiveCont f2 producer2))  {-|-    Consume the producers concurrently, and each one independently of the other. +    Consume the producers concurrently, each one independently of the other.  -} separated :: Fold1 b1 e r1 -> Fold1 b2 e r2 -> Fold2 b1 b2 e (r1,r2) separated f1 f2 = Fold2 (Other (separated_ (unLift . runFold1 $ f1) (unLift . runFold1 $ f2)))  {-|     Consume the producers concurrently, delimiting groups in each producer,-and writing the groups into a common 'Fold1'. +    and writing the groups into a common 'Fold1'.  -    Possible use: find lines in two text producers and combine them in a single-stream, preserving the integrity of each individual line.+    Possible use: find lines in two text producers and combine the lines in a+    single stream, preserving the integrity of each individual line. -} combined :: Transducer Delimited b1 e x -> Transducer Delimited b2 e x -> Fold1 x e a -> Fold2 b1 b2 e a combined t1 t2 f = Fold2 (Other (Both (\producer1 producer2 -> do    (outbox, inbox, seal) <- spawn' (bounded 1)    lock <- newMVar outbox    runConceit $ -       (\((),r1) ((),r2) (a,()) -> (a,r1,r2))+       (\(((),r1),((),r2)) (a,()) -> (a,r1,r2))        <$>-       Conceit (fold1Fallibly (transduce1 (folds (withCont' (iterTLines lock)) t1) (pure ())) producer1 `finally` atomically seal)-       <*>-       Conceit (fold1Fallibly (transduce1 (folds (withCont' (iterTLines lock)) t2) (pure ())) producer2 `finally` atomically seal)+       Conceit +           ((runConceit $+               (,)+               <$>+               Conceit (fold1Fallibly (transduce1 (folds (withCont' (iterTLines lock)) t1) (pure ())) producer1)+               <*>+               Conceit (fold1Fallibly (transduce1 (folds (withCont' (iterTLines lock)) t2) (pure ())) producer2)+           ) `finally` atomically seal)        <*>        Conceit (fold1Fallibly f (fromInput inbox) `finally` atomically seal))))   where
tests/tests.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE OverloadedStrings #-}+ module Main where  import Prelude hiding (splitAt,lines,words)@@ -9,6 +11,11 @@ import Test.Tasty import Test.Tasty.HUnit +import Control.Concurrent (threadDelay)++import Pipes+import Pipes.Transduce+import qualified Pipes.Transduce.Text as PT import qualified Data.Text as T import qualified Data.Text.Lazy as TL @@ -20,4 +27,21 @@ tests :: TestTree tests =      testGroup "Tests" -    []+    [+        testMissingDataInCombined+    ]++testMissingDataInCombined :: TestTree+testMissingDataInCombined = testCase "collectStdoutStderrAsByteString" $ do+    r <- fold2 combinedLines producer1 producer2 +    case r of+        ("aa\nbb\ncc\ndd\n",_,_) -> return ()+        _ -> assertFailure $ "did not expect" ++ show r+    where+    producer1 = do+        yield "aa\nbb\n"+    producer2 = do+        liftIO $ threadDelay 300000+        yield "cc\ndd\n"+    combinedLines = combined (PT.lines PT.utf8x) (PT.lines PT.utf8x) PT.intoLazyText+