@@ -269,9 +269,9 @@ module Streamly.Internal.Prelude
269 , reverse'
269 , reverse'
271 -- ** Parsing
271 -- ** Parsing
272− , splitParse
272+ , parseMany
273− , splitParseTill
273+ , parseManyTill
274− , concatParse
274+ , parseIterate
276 -- ** Trimming
276 -- ** Trimming
@@ -3142,13 +3142,8 @@ concatMapTreeYieldLeavesWith combine f = concatMapLoopWith combine f yield
3142------------------------------------------------------------------------------
3142------------------------------------------------------------------------------
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.
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.
3153-- XXX We need takeGE/takeBetween to implement "some" using "many".
3148-- XXX We need takeGE/takeBetween to implement "some" using "many".
@@ -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.
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]
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"]
3167-- /Internal
3162-- /Internal
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)
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 =
3184-- /Unimplemented/
3179-- /Unimplemented/
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
3195−-- Rename to iterateParse?
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.
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]
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
3207-- /Internal/
3200-- /Internal/
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)
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)
3219------------------------------------------------------------------------------
3212------------------------------------------------------------------------------
3220-- Grouping/Splitting
3213-- Grouping/Splitting