@@ -170,6 +170,7 @@ import Streamly.Internal.Data.Stream.IsStream.Common
170 , intersperseM
170 , intersperseM
172 , scanlMAfter'
172 , scanlMAfter'
173 , splitOnSeq
174 , splitOnSeq
174 , fromPure)
175 , fromPure)
175import Streamly.Internal.Data.Stream.IsStream.Type
176import Streamly.Internal.Data.Stream.IsStream.Type
@@ -251,27 +252,6 @@ dropSuffix = error "Not implemented yet!"
252-- XXX We need takeGE/takeBetween to implement "some" using "many".
253-- XXX We need takeGE/takeBetween to implement "some" using "many".
254−-- | Like 'foldMany' but appends empty fold output if the fold and stream
255−-- termination aligns:
257−-- >>> f = Fold.take 2 Fold.sum
258−-- >>> Stream.toList $ Stream.foldManyPost f $ Stream.fromList []
260−-- >>> Stream.toList $ Stream.foldManyPost f $ Stream.fromList [1..9]
262−-- >>> Stream.toList $ Stream.foldManyPost f $ Stream.fromList [1..10]
267−{-# INLINE foldManyPost #-}
269− :: (IsStream t, Monad m)
273−foldManyPost f m = fromStreamD $ D.foldManyPost f (toStreamD m)
275-- | Apply a 'Fold' repeatedly on a stream and emit the fold outputs in the
255-- | Apply a 'Fold' repeatedly on a stream and emit the fold outputs in the
276-- output stream.
256-- output stream.
@@ -889,6 +869,8 @@ splitBySeq patt f m =
890-- > splitSuffixOn . intercalateSuffix == id
870-- > splitSuffixOn . intercalateSuffix == id
872+-- >>> splitOnSuffixSeq pat f = Stream.foldMany (Fold.takeEndBySeq_ pat f)
892-- /Pre-release/
874-- /Pre-release/
893{-# INLINE splitOnSuffixSeq #-}
875{-# INLINE splitOnSuffixSeq #-}
894splitOnSuffixSeq
876splitOnSuffixSeq
@@ -896,6 +878,11 @@ splitOnSuffixSeq
896 => Array a -> Fold m a b -> t m a -> t m b
878 => Array a -> Fold m a b -> t m a -> t m b
897splitOnSuffixSeq patt f m =
879splitOnSuffixSeq patt f m =
898 fromStreamD $ D.splitOnSuffixSeq False patt f (toStreamD m)
880 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)
900-- | Like 'splitOn' but drops any empty splits.
887-- | Like 'splitOn' but drops any empty splits.
@@ -934,6 +921,8 @@ wordsOn _subseq _f _m =
934-- >>> splitWithSuffixSeq' "." "a..b.."
921-- >>> splitWithSuffixSeq' "." "a..b.."
935-- ["a.",".","b.","."]
922-- ["a.",".","b.","."]
924+-- >>> splitWithSuffixSeq pat f = Stream.foldMany (Fold.takeEndBySeq pat f)
937-- /Pre-release/
926-- /Pre-release/
938{-# INLINE splitWithSuffixSeq #-}
927{-# INLINE splitWithSuffixSeq #-}
939splitWithSuffixSeq
928splitWithSuffixSeq
@@ -941,6 +930,8 @@ splitWithSuffixSeq
941 => Array a -> Fold m a b -> t m a -> t m b
930 => Array a -> Fold m a b -> t m a -> t m b
942splitWithSuffixSeq patt f m =
931splitWithSuffixSeq patt f m =
943 fromStreamD $ D.splitOnSuffixSeq True patt f (toStreamD m)
932 fromStreamD $ D.splitOnSuffixSeq True patt f (toStreamD m)
933+-- splitWithSuffixSeq patt f =
934+-- foldMany (FL.takeEndBySeq patt f)
945-- This can be implemented easily using Rabin Karp
936-- This can be implemented easily using Rabin Karp
946-- | Split post any one of the given patterns.
937-- | Split post any one of the given patterns.