packages feed

conduit-combinators 0.2.6.1 → 0.2.7

raw patch · 4 files changed

+59/−1 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Conduit: slidingWindowC :: (Monad m, IsSequence seq, Element seq ~ a) => Int -> Conduit a m seq
+ Data.Conduit.Combinators: slidingWindow :: (Monad m, IsSequence seq, Element seq ~ a) => Int -> Conduit a m seq

Files

Data/Conduit/Combinators.hs view
@@ -5,6 +5,7 @@ {-# LANGUAGE MultiParamTypeClasses     #-} {-# LANGUAGE NoImplicitPrelude         #-} {-# LANGUAGE NoMonomorphismRestriction #-}+{-# LANGUAGE BangPatterns #-} -- | This module is meant as a replacement for Data.Conduit.List. -- That module follows a naming scheme which was originally inspired -- by its enumerator roots. This module is meant to introduce a naming@@ -140,6 +141,7 @@     , scanl     , concatMapAccum     , intersperse+    , slidingWindow        -- *** Binary base encoding     , encodeBase64@@ -1405,6 +1407,27 @@   where     go y = yield y >> concatMap (\z -> [x, z]) {-# INLINE intersperse #-}++-- | Sliding window of values+-- 1,2,3,4,5 with window size 2 gives+-- [1,2],[2,3],[3,4],[4,5]+--+-- Best used with structures that support O(1) snoc.+--+-- Since 1.0.0+slidingWindow :: (Monad m, Seq.IsSequence seq, Element seq ~ a) => Int -> Conduit a m seq+slidingWindow sz = go (if sz <= 0 then 1 else sz) mempty+    where goContinue st = await >>=+                          maybe (return ())+                                (\x -> do+                                   let st' = Seq.snoc st x+                                   yield st' >> goContinue (Seq.unsafeTail st')+                                )+          go 0 st = yield st >> goContinue (Seq.unsafeTail st)+          go !n st = CL.head >>= \m ->+                     case m of+                       Nothing -> yield st+                       Just x -> go (n-1) (Seq.snoc st x)  codeWith :: Monad m          => Int
Data/Conduit/Combinators/Unqualified.hs view
@@ -7,6 +7,7 @@ {-# LANGUAGE MultiParamTypeClasses     #-} {-# LANGUAGE NoImplicitPrelude         #-} {-# LANGUAGE NoMonomorphismRestriction #-}+{-# LANGUAGE BangPatterns #-} module Data.Conduit.Combinators.Unqualified     ( -- ** Producers       -- *** Pure@@ -129,6 +130,7 @@     , scanlC     , concatMapAccumC     , intersperseC+    , slidingWindowC        -- **** Binary base encoding     , encodeBase64C@@ -1155,6 +1157,17 @@ intersperseC :: Monad m => a -> Conduit a m a intersperseC = CC.intersperse {-# INLINE intersperseC #-}++-- | Sliding window of values+-- 1,2,3,4,5 with window size 2 gives+-- [1,2],[2,3],[3,4],[4,5]+--+-- Best used with structures that support O(1) snoc.+--+-- Since 1.0.0+slidingWindowC :: (Monad m, Seq.IsSequence seq, Element seq ~ a) => Int -> Conduit a m seq+slidingWindowC = CC.slidingWindow+{-# INLINE slidingWindowC #-}  -- | Apply base64-encoding to the stream. --
conduit-combinators.cabal view
@@ -1,5 +1,5 @@ name:                conduit-combinators-version:             0.2.6.1+version:             0.2.7 synopsis:            Commonly used conduit functions, for both chunked and unchunked data description:         Provides a replacement for Data.Conduit.List, as well as a convenient Conduit module. homepage:            https://github.com/fpco/conduit-combinators
test/Spec.hs view
@@ -5,6 +5,7 @@ import Prelude hiding (FilePath) import Data.Maybe (listToMaybe) import Data.Conduit.Combinators.Internal+import Data.Conduit.Combinators (slidingWindow) import Data.List (intersperse, sort, find) import Filesystem.Path (hasExtension) import Filesystem.Path.CurrentOS (encodeString)@@ -587,6 +588,27 @@         res1 `shouldBe` cnt * (seed + delta)         res2 <- initRepeatConnect (return seed) (return . (+ delta)) sink         res2 `shouldBe` res1+    it "slidingWindow 0" $+        let res = runIdentity $ yieldMany [1..5] $= slidingWindow 0 $$ sinkList+        in res `shouldBe` [[1],[2],[3],[4],[5]]+    it "slidingWindow 1" $+        let res = runIdentity $ yieldMany [1..5] $= slidingWindow 1 $$ sinkList+        in res `shouldBe` [[1],[2],[3],[4],[5]]+    it "slidingWindow 2" $+        let res = runIdentity $ yieldMany [1..5] $= slidingWindow 2 $$ sinkList+        in res `shouldBe` [[1,2],[2,3],[3,4],[4,5]]+    it "slidingWindow 3" $+        let res = runIdentity $ yieldMany [1..5] $= slidingWindow 3 $$ sinkList+        in res `shouldBe` [[1,2,3],[2,3,4],[3,4,5]]+    it "slidingWindow 4" $+        let res = runIdentity $ yieldMany [1..5] $= slidingWindow 4 $$ sinkList+        in res `shouldBe` [[1,2,3,4],[2,3,4,5]]+    it "slidingWindow 5" $+        let res = runIdentity $ yieldMany [1..5] $= slidingWindow 5 $$ sinkList+        in res `shouldBe` [[1,2,3,4,5]]+    it "slidingWindow 6" $+        let res = runIdentity $ yieldMany [1..5] $= slidingWindow 6 $$ sinkList+        in res `shouldBe` [[1,2,3,4,5]]  evenInt :: Int -> Bool evenInt = even