potoki-core 2.2.7 → 2.2.8
raw patch · 3 files changed
+27/−8 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Potoki.Core.Transform: count :: Transform a Int
+ Potoki.Core.Transform: handleCount :: (Int -> IO ()) -> Transform a a
+ Potoki.Core.Transform: mapInIOWithCounter :: (Int -> a -> IO b) -> Transform a b
Files
- library/Potoki/Core/Transform.hs +3/−0
- library/Potoki/Core/Transform/Basic.hs +23/−7
- potoki-core.cabal +1/−1
library/Potoki/Core/Transform.hs view
@@ -40,6 +40,9 @@ appendBytesToFile, writeTextToFile, -- * Debugging+ count,+ mapInIOWithCounter,+ handleCount, traceWithCounter, ) where
library/Potoki/Core/Transform/Basic.hs view
@@ -125,17 +125,33 @@ Transform acquire <- liftIO io acquire fetch +count :: Transform a Int+count = Transform $ \ (Fetch fetchIO) -> do+ counter <- liftIO (newIORef 0)+ return $ Fetch $ do+ result <- fetchIO+ case result of+ Just _ -> Just <$> atomicModifyIORef' counter (\ n -> (succ n, n))+ Nothing -> return Nothing++mapInIOWithCounter :: (Int -> a -> IO b) -> Transform a b+mapInIOWithCounter handler =+ ioTransform $ do+ counter <- newIORef 0+ return $ mapInIO $ \ a -> do+ count <- atomicModifyIORef' counter (\ n -> (succ n, n))+ handler count a++handleCount :: (Int -> IO ()) -> Transform a a+handleCount handler = mapInIOWithCounter $ \ count a -> do+ handler count+ return a+ {-| Useful for debugging -} traceWithCounter :: (Int -> String) -> Transform a a-traceWithCounter showFunc =- ioTransform $ do- counter <- newIORef 0- return $ mapInIO $ \ x -> do- n <- atomicModifyIORef' counter (\ n -> (succ n, n))- putStrLn (showFunc n)- return x+traceWithCounter shower = handleCount (putStrLn . shower) {-# INLINE consume #-} consume :: Consume input output -> Transform input output
potoki-core.cabal view
@@ -1,5 +1,5 @@ name: potoki-core-version: 2.2.7+version: 2.2.8 synopsis: Low-level components of "potoki" description: Provides everything required for building custom instances of