on master help sign in
rename splitParse/parseMany, concatParse/parseIterate
633c55eHarendra Kumar
benchmark/FileIO.hs+6−6
@@ -212,12 +212,12 @@ main = do
212 , mkBench "sumChunksOf 1" href $ do
212 , mkBench "sumChunksOf 1" href $ do
213 Handles inh _ <- readIORef href
213 Handles inh _ <- readIORef href
214 BFS.chunksOfSum 1 inh
214 BFS.chunksOfSum 1 inh
215− , mkBench "sumChunksOf (single chunk) (splitParse)" href $ do
215+ , mkBench "sumChunksOf (single chunk) (parseMany)" href $ do
216 Handles inh _ <- readIORef href
216 Handles inh _ <- readIORef href
217− BFS.splitParseChunksOfSum fileSize inh
217+ BFS.parseManyChunksOfSum fileSize inh
218− , mkBench "sumChunksOf 1 (splitParse)" href $ do
218+ , mkBench "sumChunksOf 1 (parseMany)" href $ do
219 Handles inh _ <- readIORef href
219 Handles inh _ <- readIORef href
220− BFS.splitParseChunksOfSum 1 inh
220+ BFS.parseManyChunksOfSum 1 inh
221
221
222 , mkBench "arraysOf 1" href $ do
222 , mkBench "arraysOf 1" href $ do
223 Handles inh _ <- readIORef href
223 Handles inh _ <- readIORef href
@@ -268,9 +268,9 @@ main = do
268 , mkBench "splitOnSuffix \\n (line count)" href $ do
268 , mkBench "splitOnSuffix \\n (line count)" href $ do
269 Handles inh _ <- readIORef href
269 Handles inh _ <- readIORef href
270 BFS.splitOnSuffix inh
270 BFS.splitOnSuffix inh
271− , mkBench "splitOn \\n (line count) (splitParse)" href $ do
271+ , mkBench "splitOn \\n (line count) (parseMany)" href $ do
272 Handles inh _ <- readIORef href
272 Handles inh _ <- readIORef href
273− BFS.splitParseSepBy inh
273+ BFS.parseManySepBy inh
274 , mkBench "wordsBy isSpace (word count)" href $ do
274 , mkBench "wordsBy isSpace (word count)" href $ do
275 Handles inh _ <- readIORef href
275 Handles inh _ <- readIORef href
276 BFS.wordsBy inh
276 BFS.wordsBy inh
benchmark/Streamly/Benchmark/Data/Parser.hs+10−10
@@ -177,20 +177,20 @@ choice value =
177-- Stream transformation
177-- Stream transformation
178-------------------------------------------------------------------------------
178-------------------------------------------------------------------------------
179
179
180−{-# INLINE splitParse #-}
180+{-# INLINE parseMany #-}
181−splitParse :: MonadCatch m => SerialT m Int -> m ()
181+parseMany :: MonadCatch m => SerialT m Int -> m ()
182−splitParse =
182+parseMany =
183 S.drain
183 S.drain
184 . S.map getSum
184 . S.map getSum
185− . IP.splitParse (PR.take 2 FL.mconcat)
185+ . IP.parseMany (PR.take 2 FL.mconcat)
186 . S.map Sum
186 . S.map Sum
187
187
188−{-# INLINE concatParse #-}
188+{-# INLINE parseIterate #-}
189−concatParse :: MonadCatch m => SerialT m Int -> m ()
189+parseIterate :: MonadCatch m => SerialT m Int -> m ()
190−concatParse =
190+parseIterate =
191 S.drain
191 S.drain
192 . S.map getSum
192 . S.map getSum
193− . IP.concatParse (\b -> (PR.take 2 (FL.mconcatTo b))) (Sum 0)
193+ . IP.parseIterate (\b -> (PR.take 2 (FL.mconcatTo b))) (Sum 0)
194 . S.map Sum
194 . S.map Sum
195
195
196-------------------------------------------------------------------------------
196-------------------------------------------------------------------------------
@@ -211,8 +211,8 @@ o_1_space_serial_parse value =
211 , benchIOSink value "teeFst (all,any)" $ teeFstAllAny value
211 , benchIOSink value "teeFst (all,any)" $ teeFstAllAny value
212 , benchIOSink value "shortest (all,any)" $ shortestAllAny value
212 , benchIOSink value "shortest (all,any)" $ shortestAllAny value
213 , benchIOSink value "longest (all,any)" $ longestAllAny value
213 , benchIOSink value "longest (all,any)" $ longestAllAny value
214− , benchIOSink value "splitParse" splitParse
214+ , benchIOSink value "parseMany" parseMany
215− , benchIOSink value "concatParse" concatParse
215+ , benchIOSink value "parseIterate" parseIterate
216 ]
216 ]
217
217
218o_n_heap_serial_parse :: Int -> [Benchmark]
218o_n_heap_serial_parse :: Int -> [Benchmark]
benchmark/Streamly/Benchmark/FileIO/Stream.hs+11−11
@@ -57,12 +57,12 @@ module Streamly.Benchmark.FileIO.Stream
57 , decodeUtf8Lax
57 , decodeUtf8Lax
58 , copyCodecUtf8Lenient
58 , copyCodecUtf8Lenient
59 , chunksOfSum
59 , chunksOfSum
60− , splitParseChunksOfSum
60+ , parseManyChunksOfSum
61 , chunksOf
61 , chunksOf
62 , chunksOfD
62 , chunksOfD
63 , splitOn
63 , splitOn
64 , splitOnSuffix
64 , splitOnSuffix
65− , splitParseSepBy
65+ , parseManySepBy
66 , wordsBy
66 , wordsBy
67 , splitOnSeq
67 , splitOnSeq
68 , splitOnSeqUtf8
68 , splitOnSeqUtf8
@@ -445,10 +445,10 @@ inspect $ 'chunksOfD `hasNoType` ''AT.FlattenState
445inspect $ 'chunksOfD `hasNoType` ''D.ConcatMapUState
445inspect $ 'chunksOfD `hasNoType` ''D.ConcatMapUState
446#endif
446#endif
447
447
448−{-# INLINE splitParseChunksOfSum #-}
448+{-# INLINE parseManyChunksOfSum #-}
449−splitParseChunksOfSum :: Int -> Handle -> IO Int
449+parseManyChunksOfSum :: Int -> Handle -> IO Int
450−splitParseChunksOfSum n inh =
450+parseManyChunksOfSum n inh =
451− S.length $ IP.splitParse (PR.take n FL.sum) (S.unfold FH.read inh)
451+ S.length $ IP.parseMany (PR.take n FL.sum) (S.unfold FH.read inh)
452
452
453{-# INLINE linesUnlinesCopy #-}
453{-# INLINE linesUnlinesCopy #-}
454linesUnlinesCopy :: Handle -> Handle -> IO ()
454linesUnlinesCopy :: Handle -> Handle -> IO ()
@@ -609,11 +609,11 @@ inspect $ 'splitOnSuffix `hasNoType` ''D.ConcatMapUState
609#endif
609#endif
610
610
611-- | Split on line feed.
611-- | Split on line feed.
612−{-# INLINE splitParseSepBy #-}
612+{-# INLINE parseManySepBy #-}
613−splitParseSepBy :: Handle -> IO Int
613+parseManySepBy :: Handle -> IO Int
614−splitParseSepBy inh =
614+parseManySepBy inh =
615− (S.length $ IP.splitParse (PR.sliceSepBy (== lf) FL.drain)
615+ (S.length $ IP.parseMany (PR.sliceSepBy (== lf) FL.drain)
616− (S.unfold FH.read inh)) -- >>= print
616+ (S.unfold FH.read inh)) -- >>= print
617
617
618-- | Words by space
618-- | Words by space
619{-# INLINE wordsBy #-}
619{-# INLINE wordsBy #-}
src/Streamly/Internal/Data/Stream/StreamD.hs+9−9
@@ -129,8 +129,8 @@ module Streamly.Internal.Data.Stream.StreamD
129 , runFold
129 , runFold
130
130
131 , parselMx'
131 , parselMx'
132− , splitParse
132+ , parseMany
133− , concatParse
133+ , parseIterate
134
134
135 -- ** Specialized Folds
135 -- ** Specialized Folds
136 , tap
136 , tap
@@ -955,7 +955,7 @@ foldlS fstep begin (Stream step state) = Stream step' (Left (state, begin))
955------------------------------------------------------------------------------
955------------------------------------------------------------------------------
956
956
957-- Inlined definition. Without the inline "serially/parser/take" benchmark
957-- Inlined definition. Without the inline "serially/parser/take" benchmark
958−-- degrades and splitParse does not fuse. Even using "inline" at the callsite
958+-- degrades and parseMany does not fuse. Even using "inline" at the callsite
959-- does not help.
959-- does not help.
960{-# INLINE splitAt #-}
960{-# INLINE splitAt #-}
961splitAt :: Int -> [a] -> ([a],[a])
961splitAt :: Int -> [a] -> ([a],[a])
@@ -1038,13 +1038,13 @@ data ParseChunksState x inpBuf st pst =
1038 | ParseChunksBuf inpBuf st inpBuf pst
1038 | ParseChunksBuf inpBuf st inpBuf pst
1039 | ParseChunksYield x (ParseChunksState x inpBuf st pst)
1039 | ParseChunksYield x (ParseChunksState x inpBuf st pst)
1040
1040
1041−{-# INLINE_NORMAL splitParse #-}
1041+{-# INLINE_NORMAL parseMany #-}
1042−splitParse
1042+parseMany
1043 :: MonadThrow m
1043 :: MonadThrow m
1044 => PRD.Parser m a b
1044 => PRD.Parser m a b
1045 -> Stream m a
1045 -> Stream m a
1046 -> Stream m b
1046 -> Stream m b
1047−splitParse (PRD.Parser pstep initial extract) (Stream step state) =
1047+parseMany (PRD.Parser pstep initial extract) (Stream step state) =
1048 Stream stepOuter (ParseChunksInit [] state)
1048 Stream stepOuter (ParseChunksInit [] state)
1049
1049
1050 where
1050 where
@@ -1130,14 +1130,14 @@ data ConcatParseState x inpBuf st p =
1130 | ConcatParseBuf inpBuf st inpBuf p
1130 | ConcatParseBuf inpBuf st inpBuf p
1131 | ConcatParseYield x (ConcatParseState x inpBuf st p)
1131 | ConcatParseYield x (ConcatParseState x inpBuf st p)
1132
1132
1133−{-# INLINE_NORMAL concatParse #-}
1133+{-# INLINE_NORMAL parseIterate #-}
1134−concatParse
1134+parseIterate
1135 :: MonadThrow m
1135 :: MonadThrow m
1136 => (b -> PRD.Parser m a b)
1136 => (b -> PRD.Parser m a b)
1137 -> b
1137 -> b
1138 -> Stream m a
1138 -> Stream m a
1139 -> Stream m b
1139 -> Stream m b
1140−concatParse func seed (Stream step state) =
1140+parseIterate func seed (Stream step state) =
1141 Stream stepOuter (ConcatParseInit [] state (func seed))
1141 Stream stepOuter (ConcatParseInit [] state (func seed))
1142
1142
1143 where
1143 where
src/Streamly/Internal/Prelude.hs+20−27
@@ -269,9 +269,9 @@ module Streamly.Internal.Prelude
269 , reverse'
269 , reverse'
270
270
271 -- ** Parsing
271 -- ** Parsing
272− , splitParse
272+ , parseMany
273− , splitParseTill
273+ , parseManyTill
274− , concatParse
274+ , parseIterate
275
275
276 -- ** Trimming
276 -- ** Trimming
277 , take
277 , take
@@ -3142,13 +3142,8 @@ concatMapTreeYieldLeavesWith combine f = concatMapLoopWith combine f yield
3142------------------------------------------------------------------------------
3142------------------------------------------------------------------------------
3143
3143
3144-- Splitting operations that take a predicate and a Fold can be
3144-- Splitting operations that take a predicate and a Fold can be
3145−-- expressed using splitParse. Operations like chunksOf, intervalsOf, split*,
3145+-- expressed using parseMany. Operations like chunksOf, intervalsOf, split*,
3146−-- can be expressed using splitParse when used with an appropriate Parse.
3146+-- can be expressed using parseMany when used with an appropriate Parser.
3147−--
3148−-- The name splitParse is supposed to be opposite of concatMap. Alternative
3149−-- names could be "many", "parseMany" or "splitMany"? If we are going to have a
3150−-- separate combinators for Fold and Parser then having fold/parse in the name
3151−-- allows the distinction.
3152--
3147--
3153-- XXX We need takeGE/takeBetween to implement "some" using "many".
3148-- XXX We need takeGE/takeBetween to implement "some" using "many".
3154
3149
@@ -3158,24 +3153,24 @@ concatMapTreeYieldLeavesWith combine f = concatMapLoopWith combine f yield
3158-- This is the streaming equivalent of the 'Streamly.Internal.Data.Parser.many'
3153-- This is the streaming equivalent of the 'Streamly.Internal.Data.Parser.many'
3159-- parse combinator.
3154-- parse combinator.
3160--
3155--
3161−-- >>> S.toList $ S.splitParse (PR.take 2 $ PR.fromFold FL.sum) $ S.fromList [1..10]
3156+-- >>> S.toList $ S.parseMany (PR.take 2 $ PR.fromFold FL.sum) $ S.fromList [1..10]
3162-- > [3,7,11,15,19]
3157-- > [3,7,11,15,19]
3163--
3158--
3164−-- >>> S.toList $ S.splitParse (PR.line FL.toList) $ S.fromList "hello\nworld"
3159+-- >>> S.toList $ S.parseMany (PR.line FL.toList) $ S.fromList "hello\nworld"
3165-- > ["hello\n","world"]
3160-- > ["hello\n","world"]
3166--
3161--
3167-- /Internal
3162-- /Internal
3168--
3163--
3169−{-# INLINE splitParse #-}
3164+{-# INLINE parseMany #-}
3170−splitParse
3165+parseMany
3171 :: (IsStream t, MonadThrow m)
3166 :: (IsStream t, MonadThrow m)
3172 => Parser m a b
3167 => Parser m a b
3173 -> t m a
3168 -> t m a
3174 -> t m b
3169 -> t m b
3175−splitParse p m =
3170+parseMany p m =
3176− D.fromStreamD $ D.splitParse (PRD.fromParserK p) (D.toStreamD m)
3171+ D.fromStreamD $ D.parseMany (PRD.fromParserK p) (D.toStreamD m)
3177
3172
3178−-- | @splitParseTill collect test stream@ tries the parser @test@ on the input,
3173+-- | @parseManyTill collect test stream@ tries the parser @test@ on the input,
3179-- if @test@ fails it backtracks and tries @collect@, after @collect@ succeeds
3174-- if @test@ fails it backtracks and tries @collect@, after @collect@ succeeds
3180-- @test@ is tried again and so on. The parser stops when @test@ succeeds. The
3175-- @test@ is tried again and so on. The parser stops when @test@ succeeds. The
3181-- output of @test@ is discarded and the output of @collect@ is emitted in the
3176-- output of @test@ is discarded and the output of @collect@ is emitted in the
@@ -3183,22 +3178,20 @@ splitParse p m =
3183--
3178--
3184-- /Unimplemented/
3179-- /Unimplemented/
3185--
3180--
3186−{-# INLINE splitParseTill #-}
3181+{-# INLINE parseManyTill #-}
3187−splitParseTill ::
3182+parseManyTill ::
3188 -- (IsStream t, MonadThrow m) =>
3183 -- (IsStream t, MonadThrow m) =>
3189 Parser m a b
3184 Parser m a b
3190 -> Parser m a x
3185 -> Parser m a x
3191 -> t m a
3186 -> t m a
3192 -> t m b
3187 -> t m b
3193−splitParseTill = undefined
3188+parseManyTill = undefined
3194
3189
3195−-- Rename to iterateParse?
3196−--
3197-- | Iterate a parser generating function on a stream. The initial value @b@ is
3190-- | Iterate a parser generating function on a stream. The initial value @b@ is
3198-- used to generate the first parser, the parser is applied on the stream and
3191-- used to generate the first parser, the parser is applied on the stream and
3199-- the result is used to generate the next parser and so on.
3192-- the result is used to generate the next parser and so on.
3200--
3193--
3201−-- >>> S.toList $ S.map getSum $ S.concatParse (\b -> PR.take 2 (FL.mconcatTo b)) 0 $ S.map Sum $ S.fromList [1..10]
3194+-- >>> S.toList $ S.map getSum $ S.parseIterate (\b -> PR.take 2 (FL.mconcatTo b)) 0 $ S.map Sum $ S.fromList [1..10]
3202-- > [3,10,21,36,55,55]
3195-- > [3,10,21,36,55,55]
3203--
3196--
3204-- This is the streaming equivalent of monad like sequenced application of
3197-- This is the streaming equivalent of monad like sequenced application of
@@ -3206,15 +3199,15 @@ splitParseTill = undefined
3206--
3199--
3207-- /Internal/
3200-- /Internal/
3208--
3201--
3209−{-# INLINE concatParse #-}
3202+{-# INLINE parseIterate #-}
3210−concatParse
3203+parseIterate
3211 :: (IsStream t, MonadThrow m)
3204 :: (IsStream t, MonadThrow m)
3212 => (b -> Parser m a b)
3205 => (b -> Parser m a b)
3213 -> b
3206 -> b
3214 -> t m a
3207 -> t m a
3215 -> t m b
3208 -> t m b
3216−concatParse f i m = D.fromStreamD $
3209+parseIterate f i m = D.fromStreamD $
3217− D.concatParse (\b -> PRD.fromParserK $ f b) i (D.toStreamD m)
3210+ D.parseIterate (\b -> PRD.fromParserK $ f b) i (D.toStreamD m)
3218
3211
3219------------------------------------------------------------------------------
3212------------------------------------------------------------------------------
3220-- Grouping/Splitting
3213-- Grouping/Splitting