conduit-algorithms 0.0.10.1 → 0.0.11.0
raw patch · 5 files changed
+60/−7 lines, 5 files
Files
- ChangeLog +4/−0
- Data/Conduit/Algorithms.hs +5/−1
- Data/Conduit/Algorithms/Utils.hs +31/−3
- conduit-algorithms.cabal +3/−3
- tests/Tests.hs +17/−0
ChangeLog view
@@ -1,3 +1,7 @@+Version 0.0.11.0 2019-09-20 by luispedro+ * Add dispatchC conduit+ * Add deprecation warning for groupC+ Version 0.0.10.1 2019-05-31 by luispedro * Accept .zst as extension for zstandard
Data/Conduit/Algorithms.hs view
@@ -84,7 +84,11 @@ Nothing -> rest() Just (CI.HaveOutput c_next v, q') -> CI.HaveOutput (norm1insert q' c_next >>= go) v _ -> error "This situation should have been impossible (mergeC/go)"- norm1insert :: (Monad m, Ord o) => PQ.MinPQueue o (CI.Pipe () i o () m ()) -> CI.Pipe () i o () m () -> CI.Pipe () i o () m (PQ.MinPQueue o (CI.Pipe () i o () m ()))+ -- norm1insert inserts the pipe in into the queue after ensuring that the pipe is CI.HaveOutput+ norm1insert :: (Monad m, Ord o)+ => PQ.MinPQueue o (CI.Pipe () i o () m ())+ -> CI.Pipe () i o () m ()+ -> CI.Pipe () i o () m (PQ.MinPQueue o (CI.Pipe () i o () m ())) norm1insert q c@(CI.HaveOutput _ v) = return (PQ.insert v c q) norm1insert q CI.Done{} = return q norm1insert q (CI.PipeM p) = lift p >>= norm1insert q
Data/Conduit/Algorithms/Utils.hs view
@@ -1,6 +1,6 @@ {-| Module : Data.Conduit.Algorithms.Utils-Copyright : 2013-2017 Luis Pedro Coelho+Copyright : 2013-2019 Luis Pedro Coelho License : MIT Maintainer : luis@luispedro.org @@ -10,9 +10,12 @@ ( awaitJust , enumerateC , groupC+ , dispatchC ) where import qualified Data.Conduit as C+import qualified Data.Conduit.List as CL+import Data.Conduit ((.|)) import Data.Maybe (maybe) import Control.Monad (unless) @@ -41,7 +44,9 @@ enumerateC' (i + 1) {-# INLINE enumerateC #-} --- | groupC yields the input as groups of 'n' elements. If the input is not a+-- | This function is deprecated; use 'Data.Conduit.List.chunksOf'+--+-- groupC yields the input as groups of 'n' elements. If the input is not a -- multiple of 'n', the last element will be incomplete -- -- Example:@@ -52,7 +57,6 @@ -- -- results in @[ [0,1,2], [3,4,5], [6,7,8], [9, 10] ]@ ----- This function is deprecated; use 'Data.Conduit.List.chunksOf' groupC :: (Monad m) => Int -> C.ConduitT a [a] m () groupC n = loop n [] where@@ -60,4 +64,28 @@ loop c ps = C.await >>= \case Nothing -> unless (null ps) $ C.yield (reverse ps) Just p -> loop (c-1) (p:ps)+{-# WARNING groupC "This function is deprecated; use 'Data.Conduit.List.chunksOf'" #-} +-- | dispatchC dispatches indexed input to the respective sink+-- +-- Example:+--+-- @+-- let input = [(0, "one")+-- ,(1, "two")+-- ,(0, "three")+-- ]+-- CC.yieldMany .| dispatches [sink1, sink2]+-- @+--+-- Then 'sink1' will receive "one" and "three", while 'sink2' will receive "two"+--+-- Out of bounds indices are clipped to the 0..n-1 range (where 'n' is 'length sinks')+dispatchC :: Monad m => [C.ConduitT a C.Void m r] -> C.ConduitT (Int, a) C.Void m [r]+dispatchC sinks = C.sequenceSinks [select i .| s | (i,s) <- zip [0..] sinks]+ where+ n = length sinks+ select i = CL.mapMaybe $ \(j,val) ->+ if j == i || (i == n - 1 && j >= n) || (i == 0 && j < 0)+ then Just val+ else Nothing
conduit-algorithms.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.1.+-- This file has been generated from package.yaml by hpack version 0.31.2. -- -- see: https://github.com/sol/hpack ----- hash: 970b58ff0d5b7502e92faea1119a63d4779237c3e4c31595392ce40d3cad6957+-- hash: 93525d4124a62b6b071240ceaaf942dfa47aaf1316df09321dc68cb9cdde507a name: conduit-algorithms-version: 0.0.10.1+version: 0.0.11.0 synopsis: Conduit-based algorithms description: Algorithms on Conduits, including higher level asynchronous processing and some other utilities. category: Conduit
tests/Tests.hs view
@@ -306,3 +306,20 @@ let v = VS.fromList [0:: Int, 1, 2, 4, 6, 12] vals <- extractIO (CC.yieldMany [v,v,v] .| CAlg.writeStorableV .| CAlg.readStorableV 3) VS.concat vals @=? VS.concat [v,v,v]++case_dispatchC :: IO ()+case_dispatchC = do+ let v = [(0 :: Int, 0 :: Int),+ (0, 1),+ (1, 1),+ (0, 2),+ (-1, 3),+ (2, -1),+ (2, -1),+ (3, -1),+ (2, -1)+ ]+ acc !n = C.await >>= \case+ Nothing -> return n+ Just x -> acc (n + x)+ C.runConduitPure (CC.yieldMany v .| CAlg.dispatchC [acc i | i <- [0 :: Int ..2]]) @=? [6,2,-2 :: Int]