on master help sign in
Rename fold_/parse_/foldOn
e715e4aHarendra Kumar
core/src/Streamly/Internal/Data/Stream/StreamD/Eliminate.hs+5−5
@@ -17,7 +17,7 @@ module Streamly.Internal.Data.Stream.StreamD.Eliminate
17
17
18 -- -- * Running a 'Parser'
18 -- -- * Running a 'Parser'
19 , parse
19 , parse
20− , parse_
20+ , parseBreak
21
21
22 -- * Stream Deconstruction
22 -- * Stream Deconstruction
23 , uncons
23 , uncons
@@ -141,17 +141,17 @@ parse
141 -> Stream m a
141 -> Stream m a
142 -> m b
142 -> m b
143parse parser strm = do
143parse parser strm = do
144− (b, _) <- parse_ parser strm
144+ (b, _) <- parseBreak parser strm
145 return b
145 return b
146
146
147-- | Run a 'Parse' over a stream and return rest of the Stream.
147-- | Run a 'Parse' over a stream and return rest of the Stream.
148−{-# INLINE_NORMAL parse_ #-}
148+{-# INLINE_NORMAL parseBreak #-}
149−parse_
149+parseBreak
150 :: MonadThrow m
150 :: MonadThrow m
151 => PRD.Parser m a b
151 => PRD.Parser m a b
152 -> Stream m a
152 -> Stream m a
153 -> m (b, Stream m a)
153 -> m (b, Stream m a)
154−parse_ (PRD.Parser pstep initial extract) stream@(Stream step state) = do
154+parseBreak (PRD.Parser pstep initial extract) stream@(Stream step state) = do
155 res <- initial
155 res <- initial
156 case res of
156 case res of
157 PRD.IPartial s -> go SPEC state (List []) s
157 PRD.IPartial s -> go SPEC state (List []) s
core/src/Streamly/Internal/Data/Stream/StreamD/Type.hs+9−9
@@ -42,8 +42,8 @@ module Streamly.Internal.Data.Stream.StreamD.Type
42
42
43 -- * Running a 'Fold'
43 -- * Running a 'Fold'
44 , fold
44 , fold
45− , fold_
45+ , foldBreak
46− , foldOn
46+ , foldContinue
47
47
48 -- * Right Folds
48 -- * Right Folds
49 , foldrT
49 , foldrT
@@ -268,12 +268,12 @@ toStreamK (Stream step state) = go state
268{-# INLINE_NORMAL fold #-}
268{-# INLINE_NORMAL fold #-}
269fold :: Monad m => Fold m a b -> Stream m a -> m b
269fold :: Monad m => Fold m a b -> Stream m a -> m b
270fold fld strm = do
270fold fld strm = do
271− (b, _) <- fold_ fld strm
271+ (b, _) <- foldBreak fld strm
272 return b
272 return b
273
273
274−{-# INLINE_NORMAL fold_ #-}
274+{-# INLINE_NORMAL foldBreak #-}
275−fold_ :: Monad m => Fold m a b -> Stream m a -> m (b, Stream m a)
275+foldBreak :: Monad m => Fold m a b -> Stream m a -> m (b, Stream m a)
276−fold_ (Fold fstep begin done) (Stream step state) = do
276+foldBreak (Fold fstep begin done) (Stream step state) = do
277 res <- begin
277 res <- begin
278 case res of
278 case res of
279 FL.Partial fs -> go SPEC fs state
279 FL.Partial fs -> go SPEC fs state
@@ -295,9 +295,9 @@ fold_ (Fold fstep begin done) (Stream step state) = do
295 b <- done fs
295 b <- done fs
296 return $! (b, Stream (\ _ _ -> return Stop) ())
296 return $! (b, Stream (\ _ _ -> return Stop) ())
297
297
298−{-# INLINE_NORMAL foldOn #-}
298+{-# INLINE_NORMAL foldContinue #-}
299−foldOn :: Monad m => Fold m a b -> Stream m a -> Fold m a b
299+foldContinue :: Monad m => Fold m a b -> Stream m a -> Fold m a b
300−foldOn (Fold fstep finitial fextract) (Stream sstep state) =
300+foldContinue (Fold fstep finitial fextract) (Stream sstep state) =
301 Fold fstep initial fextract
301 Fold fstep initial fextract
302
302
303 where
303 where
src/Streamly/Internal/Data/Array/Stream/Foreign.hs+2−2
@@ -611,10 +611,10 @@ parseD (PRD.Parser pstep initial extract) stream@(D.Stream step state) = do
611{-# INLINE_NORMAL parse #-}
611{-# INLINE_NORMAL parse #-}
612parse ::
612parse ::
613 (MonadIO m, MonadThrow m, Storable a)
613 (MonadIO m, MonadThrow m, Storable a)
614− => PRD.Parser m a b
614+ => PR.Parser m a b
615 -> SerialT m (A.Array a)
615 -> SerialT m (A.Array a)
616 -> m (b, SerialT m (A.Array a))
616 -> m (b, SerialT m (A.Array a))
617−parse p s = fmap fromStreamD <$> parseD p (toStreamD s)
617+parse p s = fmap fromStreamD <$> parseD (PRD.fromParserK p) (toStreamD s)
618
618
619-------------------------------------------------------------------------------
619-------------------------------------------------------------------------------
620-- Elimination - Running Array Folds and parsers
620-- Elimination - Running Array Folds and parsers
src/Streamly/Internal/Data/Stream/IsStream/Common.hs+15−15
@@ -22,9 +22,9 @@ module Streamly.Internal.Data.Stream.IsStream.Common
22 , relTimesWith
22 , relTimesWith
23
23
24 -- * Elimination
24 -- * Elimination
25− , foldOn
25+ , foldContinue
26 , fold
26 , fold
27− , fold_
27+ , foldBreak
28
28
29 -- * Transformation
29 -- * Transformation
30 , map
30 , map
@@ -270,18 +270,18 @@ relTimesWith = fmap snd . timesWith
270-- Elimination - Running a Fold
270-- Elimination - Running a Fold
271------------------------------------------------------------------------------
271------------------------------------------------------------------------------
272
272
273−-- | We can create higher order folds using 'foldOn'. We can fold a number of
273+-- | We can create higher order folds using 'foldContinue'. We can fold a
274−-- streams to a given fold efficiently with full stream fusion. For example, to
274+-- number of streams to a given fold efficiently with full stream fusion. For
275−-- fold a list of streams on the same sum fold:
275+-- example, to fold a list of streams on the same sum fold:
276--
276--
277−-- >>> concatFold = Prelude.foldl Stream.foldOn Fold.sum
277+-- >>> concatFold = Prelude.foldl Stream.foldContinue Fold.sum
278--
278--
279−-- >>> fold f = Fold.finish . Stream.foldOn f
279+-- >>> fold f = Fold.finish . Stream.foldContinue f
280--
280--
281-- /Internal/
281-- /Internal/
282−{-# INLINE foldOn #-}
282+{-# INLINE foldContinue #-}
283−foldOn :: Monad m => Fold m a b -> SerialT m a -> Fold m a b
283+foldContinue :: Monad m => Fold m a b -> SerialT m a -> Fold m a b
284−foldOn f s = D.foldOn f $ IsStream.toStreamD s
284+foldContinue f s = D.foldContinue f $ IsStream.toStreamD s
285
285
286-- | Fold a stream using the supplied left 'Fold' and reducing the resulting
286-- | Fold a stream using the supplied left 'Fold' and reducing the resulting
287-- expression strictly at each step. The behavior is similar to 'foldl''. A
287-- expression strictly at each step. The behavior is similar to 'foldl''. A
@@ -308,13 +308,13 @@ foldOn f s = D.foldOn f $ IsStream.toStreamD s
308{-# INLINE fold #-}
308{-# INLINE fold #-}
309fold :: Monad m => Fold m a b -> SerialT m a -> m b
309fold :: Monad m => Fold m a b -> SerialT m a -> m b
310fold fl strm = do
310fold fl strm = do
311− (b, _) <- fold_ fl strm
311+ (b, _) <- foldBreak fl strm
312 return $! b
312 return $! b
313
313
314−{-# INLINE fold_ #-}
314+{-# INLINE foldBreak #-}
315−fold_ :: Monad m => Fold m a b -> SerialT m a -> m (b, SerialT m a)
315+foldBreak :: Monad m => Fold m a b -> SerialT m a -> m (b, SerialT m a)
316−fold_ fl strm = do
316+foldBreak fl strm = do
317− (b, str) <- D.fold_ fl $ IsStream.toStreamD strm
317+ (b, str) <- D.foldBreak fl $ IsStream.toStreamD strm
318 return $! (b, IsStream.fromStreamD str)
318 return $! (b, IsStream.fromStreamD str)
319
319
320------------------------------------------------------------------------------
320------------------------------------------------------------------------------
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+13−13
@@ -23,16 +23,16 @@ module Streamly.Internal.Data.Stream.IsStream.Eliminate
23 -- * Running a 'Fold'
23 -- * Running a 'Fold'
24 -- See "Streamly.Internal.Data.Fold".
24 -- See "Streamly.Internal.Data.Fold".
25 fold
25 fold
26− , fold_
26+ , foldBreak
27− , foldOn
27+ , foldContinue
28
28
29 -- * Running a 'Parser'
29 -- * Running a 'Parser'
30 -- "Streamly.Internal.Data.Parser".
30 -- "Streamly.Internal.Data.Parser".
31 , parse
31 , parse
32 , parseK
32 , parseK
33 , parseD
33 , parseD
34− , parse_
34+ , parseBreak
35− , parseD_
35+ , parseBreakD
36
36
37 -- * Stream Deconstruction
37 -- * Stream Deconstruction
38 -- | foldr and foldl do not provide the remaining stream. 'uncons' is more
38 -- | foldr and foldl do not provide the remaining stream. 'uncons' is more
@@ -162,8 +162,8 @@ import Streamly.Internal.Control.Concurrent (MonadAsync)
162import Streamly.Internal.Data.Parser (Parser (..))
162import Streamly.Internal.Data.Parser (Parser (..))
163import Streamly.Internal.Data.SVar (defState)
163import Streamly.Internal.Data.SVar (defState)
164import Streamly.Internal.Data.Stream.IsStream.Common
164import Streamly.Internal.Data.Stream.IsStream.Common
165− ( fold, fold_, foldOn, drop, findIndices, reverse, splitOnSeq, take
165+ ( fold, foldBreak, foldContinue, drop, findIndices, reverse, splitOnSeq
166− , takeWhile, mkParallel)
166+ , take , takeWhile, mkParallel)
167import Streamly.Internal.Data.Stream.IsStream.Type
167import Streamly.Internal.Data.Stream.IsStream.Type
168 (IsStream, toStreamS, fromStreamD, toStreamD)
168 (IsStream, toStreamS, fromStreamD, toStreamD)
169import Streamly.Internal.Data.Stream.Serial (SerialT(..))
169import Streamly.Internal.Data.Stream.Serial (SerialT(..))
@@ -405,19 +405,19 @@ parseK = parse
405parse :: MonadThrow m => Parser m a b -> SerialT m a -> m b
405parse :: MonadThrow m => Parser m a b -> SerialT m a -> m b
406parse = parseD . PRD.fromParserK
406parse = parseD . PRD.fromParserK
407
407
408−{-# INLINE_NORMAL parseD_ #-}
408+{-# INLINE_NORMAL parseBreakD #-}
409−parseD_ :: MonadThrow m => PRD.Parser m a b -> SerialT m a -> m (b, SerialT m a)
409+parseBreakD :: MonadThrow m => PRD.Parser m a b -> SerialT m a -> m (b, SerialT m a)
410−parseD_ parser strm = do
410+parseBreakD parser strm = do
411− (b, strmD) <- D.parse_ parser (toStreamD strm)
411+ (b, strmD) <- D.parseBreak parser (toStreamD strm)
412 return $! (b, fromStreamD strmD)
412 return $! (b, fromStreamD strmD)
413
413
414-- | Parse a stream using the supplied 'Parser'.
414-- | Parse a stream using the supplied 'Parser'.
415--
415--
416-- /Internal/
416-- /Internal/
417--
417--
418−{-# INLINE [3] parse_ #-}
418+{-# INLINE [3] parseBreak #-}
419−parse_ :: MonadThrow m => Parser m a b -> SerialT m a -> m (b, SerialT m a)
419+parseBreak :: MonadThrow m => Parser m a b -> SerialT m a -> m (b, SerialT m a)
420−parse_ = parseD_ . PRD.fromParserK
420+parseBreak = parseBreakD . PRD.fromParserK
421
421
422------------------------------------------------------------------------------
422------------------------------------------------------------------------------
423-- Specific Fold Functions
423-- Specific Fold Functions
test/Streamly/Test/Data/Array/Stream/Foreign.hs+6−6
@@ -9,7 +9,7 @@ import Test.QuickCheck.Monadic (monadicIO, run)
9import qualified Streamly.Internal.Data.Array.Foreign as Array
9import qualified Streamly.Internal.Data.Array.Foreign as Array
10import qualified Streamly.Internal.Data.Array.Stream.Foreign as ArrayStream
10import qualified Streamly.Internal.Data.Array.Stream.Foreign as ArrayStream
11import qualified Streamly.Internal.Data.Fold as Fold
11import qualified Streamly.Internal.Data.Fold as Fold
12−import qualified Streamly.Internal.Data.Parser.ParserD as ParserD
12+import qualified Streamly.Internal.Data.Parser as Parser
13import qualified Streamly.Internal.Data.Stream.IsStream as Stream
13import qualified Streamly.Internal.Data.Stream.IsStream as Stream
14import qualified Test.Hspec as Hspec
14import qualified Test.Hspec as Hspec
15
15
@@ -33,8 +33,8 @@ chooseAny = MkGen (\r _ -> let (x,_) = random r in x)
33maxTestCount :: Int
33maxTestCount :: Int
34maxTestCount = 100
34maxTestCount = 100
35
35
36−parse :: Property
36+parseBreak :: Property
37−parse = do
37+parseBreak = do
38 let len = 200
38 let len = 200
39 -- ls = input list (stream)
39 -- ls = input list (stream)
40 -- clen = chunk size
40 -- clen = chunk size
@@ -50,8 +50,8 @@ parse = do
50 let input =
50 let input =
51 Stream.chunksOf
51 Stream.chunksOf
52 clen (Array.writeN clen) (Stream.fromList ls)
52 clen (Array.writeN clen) (Stream.fromList ls)
53− parser = ParserD.fromFold (Fold.take tlen Fold.toList)
53+ parser = Parser.fromFold (Fold.take tlen Fold.toList)
54− in run $ ArrayStream.parse parser input
54+ in run $ ArrayStream.parseBreak parser input
55 ls2 <- run $ Stream.toList $ ArrayStream.concat str
55 ls2 <- run $ Stream.toList $ ArrayStream.concat str
56 listEquals (==) (ls1 ++ ls2) ls
56 listEquals (==) (ls1 ++ ls2) ls
57
57
@@ -69,4 +69,4 @@ main =
69 modifyMaxSuccess (const maxTestCount) $ do
69 modifyMaxSuccess (const maxTestCount) $ do
70 describe moduleName $ do
70 describe moduleName $ do
71 describe "Stream parsing" $ do
71 describe "Stream parsing" $ do
72− prop "parse" parse
72+ prop "parseBreak" parseBreak
test/Streamly/Test/Data/Fold.hs+4−4
@@ -547,9 +547,9 @@ many =
547
547
548 split i = FL.take i FL.toList
548 split i = FL.take i FL.toList
549
549
550−headAndRest :: [Int] -> Property
550+foldBreak :: [Int] -> Property
551−headAndRest ls = monadicIO $ do
551+foldBreak ls = monadicIO $ do
552− (mbh, rest) <- run $ Stream.fold_ FL.head (S.fromList ls)
552+ (mbh, rest) <- run $ Stream.foldBreak FL.head (S.fromList ls)
553 rests <- run $ S.toList rest
553 rests <- run $ S.toList rest
554 assert (mbh == headl ls)
554 assert (mbh == headl ls)
555 listEquals (==) rests (taill ls)
555 listEquals (==) rests (taill ls)
@@ -769,4 +769,4 @@ main = hspec $ do
769 -- concatMap
769 -- concatMap
770 -- chunksOf
770 -- chunksOf
771
771
772− prop "head from fold_" headAndRest
772+ prop "foldBreak" foldBreak