packages feed

streaming-bytestring 0.1.3.0 → 0.1.4.0

raw patch · 4 files changed

+61/−4 lines, 4 filesdep ~streaming

Dependency ranges changed: streaming

Files

Data/ByteString/Streaming.hs view
@@ -62,11 +62,14 @@     , toChunks         -- toChunks :: Monad m => ByteString m r -> Stream (Of ByteString) m r      , fromStrict       -- fromStrict :: ByteString -> ByteString m ()      , toStrict         -- toStrict :: Monad m => ByteString m () -> m ByteString -    , toStrict_        -- toStrict' :: Monad m => ByteString m r -> m (Of ByteString r) +    , toStrict_        -- toStrict_ :: Monad m => ByteString m r -> m (Of ByteString r)      , effects+    , copy     , drained     , mwrap+    , distribute       -- distribute :: ByteString (t m) a -> t (ByteString m) a      +         -- * Transforming ByteStrings     , map              -- map :: Monad m => (Word8 -> Word8) -> ByteString m r -> ByteString m r      , intercalate      -- intercalate :: Monad m => ByteString m () -> Stream (ByteString m) m r -> ByteString m r @@ -168,7 +171,6 @@ --    , hPutNonBlocking  -- hPutNonBlocking :: Handle -> ByteString IO r -> ByteString IO r      -- * Etc.     , zipWithStream    -- zipWithStream :: Monad m => (forall x. a -> ByteString m x -> ByteString m x) -> [a] -> Stream (ByteString m) m r -> Stream (ByteString m) m r -    , distribute       -- distribute :: ByteString (t m) a -> t (ByteString m) a     ) where 
Data/ByteString/Streaming/Char8.hs view
@@ -25,6 +25,7 @@     , toStrict         -- toStrict :: Monad m => ByteString m () -> m ByteString      , toStrict_     , effects+    , copy     , drained     , mwrap 
Data/ByteString/Streaming/Internal.hs view
@@ -27,6 +27,7 @@    , reread    , inlinePerformIO    , unsafeLast+   , copy        -- * ResourceT help    , bracketByteString@@ -405,3 +406,56 @@       Nothing -> return (Empty ())       Just a  -> return (Chunk a loop) {-# INLINEABLE reread #-}++{-| Make the information in a bytestring available to more than one eliminating fold, e.g.++>>>  Q.count 'l' $ Q.count 'o' $ Q.copy $ "hello\nworld"+3 :> (2 :> ())++>>> Q.length $ Q.count 'l' $ Q.count 'o' $ Q.copy $ Q.copy "hello\nworld"+11 :> (3 :> (2 :> ()))++>>> runResourceT $ Q.writeFile "hello2.txt" $ Q.writeFile "hello1.txt" $ Q.copy $ "hello\nworld\n"+>>> :! cat hello2.txt+hello+world+>>> :! cat hello1.txt+hello+world++    This sort of manipulation could as well be acheived by combining folds - using+    @Control.Foldl@ for example. But any sort of manipulation can be involved in+    the fold.  Here are a couple of trivial complications involving splitting by lines:++>>> let doubleLines = Q.unlines . maps (<* Q.chunk "\n" ) . Q.lines+>>> let emphasize = Q.unlines . maps (<* Q.chunk "!" ) . Q.lines+>>> runResourceT $ Q.writeFile "hello2.txt" $ emphasize $ Q.writeFile "hello1.txt" $ doubleLines $ Q.copy $ "hello\nworld"+>>> :! cat hello2.txt+hello!+world!+>>> :! cat hello1.txt+hello++world++    As with the parallel operations in @Streaming.Prelude@, we have++> Q.effects . Q.copy       = id+> hoist Q.effects . Q.copy = id++   The duplication does not by itself involve the copying of bytestring chunks;+   it just makes two references to each chunk as it arises. This does, however+   double the number of constructors associated with each chunk.++-}++copy+  :: Monad m =>+     ByteString m r -> ByteString (ByteString m) r+copy = loop where+  loop str = case str of+    Empty r         -> Empty r+    Go m            -> Go (liftM loop (lift m))+    Chunk bs rest   -> Chunk bs (Go (Chunk bs (Empty (loop rest))))++{-# INLINABLE copy #-}
streaming-bytestring.cabal view
@@ -1,5 +1,5 @@ name:                streaming-bytestring-version:             0.1.3.0+version:             0.1.4.0 synopsis:            effectful byte steams, or: bytestring io done right.  description:         This is an implementation of effectful, memory-constrained @@ -190,7 +190,7 @@                      , mmorph >=1.0 && <1.2                      , transformers >=0.3 && <0.5                      , transformers-base-                     , streaming >=  0.1.3.0 && <= 0.1.3.5+                     , streaming >=  0.1.4.0 && < 0.1.4.5                      , resourcet                      , exceptions   if impl(ghc < 7.8)