potoki 0.11.2 → 0.11.3
raw patch · 3 files changed
+42/−7 lines, 3 files
Files
- library/Potoki/Consume.hs +33/−6
- library/Potoki/Fetch.hs +8/−0
- potoki.cabal +1/−1
library/Potoki/Consume.hs view
@@ -11,8 +11,10 @@ vector, concat, fold,- execState, foldInIO,+ folding,+ foldingInIO,+ execState, writeBytesToFile, appendBytesToFile, deleteFiles,@@ -31,6 +33,7 @@ import qualified Potoki.Core.Produce as H import qualified Potoki.Core.Transform as J import qualified Potoki.Core.IO as L+import qualified Potoki.Fetch as A import qualified Data.ByteString as C import qualified Data.Attoparsec.ByteString as E import qualified Data.Attoparsec.Text as F@@ -149,11 +152,6 @@ build fetch !accumulator = join (fetch (pure (finish accumulator)) (\ !input -> build fetch (step accumulator input))) -{-# INLINE execState #-}-execState :: (a -> O.State s b) -> s -> Consume a s-execState stateFn initialState = - fold $ D.Fold (\currentState input -> snd $ O.runState (stateFn input) currentState) initialState id- {-# INLINABLE foldInIO #-} foldInIO :: D.FoldM IO input output -> Consume input output foldInIO (D.FoldM step init finish) =@@ -161,6 +159,35 @@ where build fetch !accumulator = join (fetch (finish accumulator) (\ !input -> step accumulator input >>= build fetch))++{-# INLINABLE folding #-}+folding :: D.Fold a b -> Consume a c -> Consume a (b, c)+folding (D.Fold step init extract) (Consume consumeIO) =+ Consume $ \ fetch -> do+ foldStateRef <- newIORef init+ consumptionResult <-+ consumeIO (A.handlingElements (\ element -> do+ !newState <- flip step element <$> readIORef foldStateRef+ writeIORef foldStateRef newState) fetch)+ foldResult <- extract <$> readIORef foldStateRef+ return (foldResult, consumptionResult)++{-# INLINABLE foldingInIO #-}+foldingInIO :: D.FoldM IO a b -> Consume a c -> Consume a (b, c)+foldingInIO (D.FoldM step init extract) (Consume consumeIO) =+ Consume $ \ fetch -> do+ foldStateRef <- newIORef =<< init+ consumptionResult <-+ consumeIO (A.handlingElements (\ element -> do+ !newState <- flip step element =<< readIORef foldStateRef+ writeIORef foldStateRef newState) fetch)+ foldResult <- extract =<< readIORef foldStateRef+ return (foldResult, consumptionResult)++{-# INLINE execState #-}+execState :: (a -> O.State s b) -> s -> Consume a s+execState stateFn initialState = + fold $ D.Fold (\currentState input -> snd $ O.runState (stateFn input) currentState) initialState id {-# INLINABLE runParseResult #-} runParseResult :: (Monoid input, Eq input) => (input -> I.IResult input output) -> Consume input (Either Text output)
library/Potoki/Fetch.hs view
@@ -96,3 +96,11 @@ writeIORef indexRef (succ index) return (just (C.unsafeIndex vector index)) else return nil++{-# INLINABLE handlingElements #-}+handlingElements :: (element -> IO ()) -> Fetch element -> Fetch element+handlingElements xRay (Fetch fetchIO) =+ Fetch $ \ nil just ->+ join $ fetchIO+ (return nil)+ (\ element -> xRay element $> just element)
potoki.cabal view
@@ -1,7 +1,7 @@ name: potoki version:- 0.11.2+ 0.11.3 synopsis: Simple streaming in IO description: