potoki-core 2.3.4 → 2.3.4.1
raw patch · 4 files changed
+21/−14 lines, 4 filessetup-changed
Files
- Setup.hs +0/−2
- library/Potoki/Core/Transform/Basic.hs +16/−11
- potoki-core.cabal +1/−1
- test/Transform.hs +4/−0
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
library/Potoki/Core/Transform/Basic.hs view
@@ -36,17 +36,22 @@ {-# INLINE drop #-} drop :: Int -> Transform input input drop amount =- Transform $ \ (A.Fetch fetchIO) -> M.Acquire $ do- countRef <- newIORef amount- return $ (, return ()) $ A.Fetch $ let- loop = do- count <- readIORef countRef- if count > 0- then do- writeIORef countRef $! pred count- loop- else fetchIO- in loop+ Transform $ \ (A.Fetch fetchIO) -> do+ countRef <- liftIO $ newIORef amount+ return $ Fetch $ do+ let+ loop = do+ count <- readIORef countRef+ fetch <- fetchIO+ case fetch of+ Just _ ->+ if count > 0+ then do+ writeIORef countRef $! pred count+ loop+ else (return fetch)+ Nothing -> return Nothing+ loop {-# INLINE list #-} list :: Transform [a] a
potoki-core.cabal view
@@ -1,5 +1,5 @@ name: potoki-core-version: 2.3.4+version: 2.3.4.1 synopsis: Low-level components of "potoki" description: Provides everything required for building custom instances of
test/Transform.hs view
@@ -42,6 +42,10 @@ concat list === unsafePerformIO (C.produceAndTransformAndConsume (E.list list) A.list D.list) ,+ testProperty "drop" $ \ (list :: [Int], n :: Int) -> + (drop n list) ===+ unsafePerformIO (C.produceAndTransformAndConsume (E.list list) (A.drop n) D.list)+ , testProperty "Applying chunksOf to list has the same effect as the \"batch\" transform" $ let gen = do list <- listOf (choose (0, 1000 :: Int))