@@ -170,6 +170,7 @@ import Streamly.Internal.Data.Stream.IsStream.Common
170170 , intersperseM
171171 , map
172172 , scanlMAfter'
173+ , foldManyPost
173174 , splitOnSeq
174175 , fromPure)
175176import Streamly.Internal.Data.Stream.IsStream.Type
@@ -251,27 +252,6 @@ dropSuffix = error "Not implemented yet!"
251252--
252253-- XXX We need takeGE/takeBetween to implement "some" using "many".
253254
254−-- | Like 'foldMany' but appends empty fold output if the fold and stream
255−-- termination aligns:
256−--
257−-- >>> f = Fold.take 2 Fold.sum
258−-- >>> Stream.toList $ Stream.foldManyPost f $ Stream.fromList []
259−-- [0]
260−-- >>> Stream.toList $ Stream.foldManyPost f $ Stream.fromList [1..9]
261−-- [3,7,11,15,9]
262−-- >>> Stream.toList $ Stream.foldManyPost f $ Stream.fromList [1..10]
263−-- [3,7,11,15,19,0]
264−--
265−-- /Pre-release/
266−--
267−{-# INLINE foldManyPost #-}
268−foldManyPost
269− :: (IsStream t, Monad m)
270− => Fold m a b
271− -> t m a
272− -> t m b
273−foldManyPost f m = fromStreamD $ D.foldManyPost f (toStreamD m)
274−
275255-- | Apply a 'Fold' repeatedly on a stream and emit the fold outputs in the
276256-- output stream.
277257--
@@ -889,6 +869,8 @@ splitBySeq patt f m =
889869--
890870-- > splitSuffixOn . intercalateSuffix == id
891871--
872+-- >>> splitOnSuffixSeq pat f = Stream.foldMany (Fold.takeEndBySeq_ pat f)
873+--
892874-- /Pre-release/
893875{-# INLINE splitOnSuffixSeq #-}
894876splitOnSuffixSeq
@@ -896,6 +878,11 @@ splitOnSuffixSeq
896878 => Array a -> Fold m a b -> t m a -> t m b
897879splitOnSuffixSeq patt f m =
898880 fromStreamD $ D.splitOnSuffixSeq False patt f (toStreamD m)
881+-- XXX This may have a problem if the stream terminates and we start extracting
882+-- the fold and then the fold terminates before consuming all the buffered
883+-- input. We have no way to supply the buffered input back to the driver.
884+-- splitOnSuffixSeq patt f =
885+-- foldMany (FL.takeEndBySeq_ patt f)
899886
900887-- | Like 'splitOn' but drops any empty splits.
901888--
@@ -934,6 +921,8 @@ wordsOn _subseq _f _m =
934921-- >>> splitWithSuffixSeq' "." "a..b.."
935922-- ["a.",".","b.","."]
936923--
924+-- >>> splitWithSuffixSeq pat f = Stream.foldMany (Fold.takeEndBySeq pat f)
925+--
937926-- /Pre-release/
938927{-# INLINE splitWithSuffixSeq #-}
939928splitWithSuffixSeq
@@ -941,6 +930,8 @@ splitWithSuffixSeq
941930 => Array a -> Fold m a b -> t m a -> t m b
942931splitWithSuffixSeq patt f m =
943932 fromStreamD $ D.splitOnSuffixSeq True patt f (toStreamD m)
933+-- splitWithSuffixSeq patt f =
934+-- foldMany (FL.takeEndBySeq patt f)
944935
945936-- This can be implemented easily using Rabin Karp
946937-- | Split post any one of the given patterns.