Skip to content

Commit

Permalink
Make the effect behaviour of splitSepBy similar to splitSepBySeq
Browse files Browse the repository at this point in the history
splitSepBySeq runs the initial effect of Fold and finalizes it on an empty
stream
  • Loading branch information
adithyaov committed Jan 7, 2025
1 parent 2551328 commit cde9fea
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions core/src/Streamly/Internal/Data/Stream/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,7 @@ catEithers = fmap (either id id)
data SplitSepBy s fs b a
= SplitSepByInit s
| SplitSepByInitFold0 s
| SplitSepByInitFold1 s a
| SplitSepByInitFold1 s fs
| SplitSepByCheck s a fs
| SplitSepByNext s fs
| SplitSepByYield b (SplitSepBy s fs b a)
Expand Down Expand Up @@ -2234,28 +2234,28 @@ splitSepBy_ predicate (Fold fstep initial _ final) (Stream step1 state1) =
-- On the other hand, in most cases the fold will not terminate without
-- consuming anything. So both ways are similar.
{-# INLINE_LATE step #-}
step gst (SplitSepByInit st) = do
r <- step1 (adaptState gst) st
case r of
Yield x s -> return $ Skip $ SplitSepByInitFold1 s x
Skip s -> return $ Skip (SplitSepByInit s)
Stop -> return Stop

step _ (SplitSepByInitFold0 st) = do
step _ (SplitSepByInit st) = do
fres <- initial
return
$ Skip
$ case fres of
FL.Done b -> SplitSepByYield b (SplitSepByInitFold0 st)
FL.Partial fs -> SplitSepByNext st fs
FL.Done b -> SplitSepByYield b (SplitSepByInit st)
FL.Partial fs -> SplitSepByInitFold1 st fs

step _ (SplitSepByInitFold1 st x) = do
step _ (SplitSepByInitFold0 st) = do
fres <- initial
return
$ Skip
$ case fres of
FL.Done b -> SplitSepByYield b (SplitSepByInitFold1 st x)
FL.Partial fs -> SplitSepByCheck st x fs
FL.Done b -> SplitSepByYield b (SplitSepByInitFold0 st)
FL.Partial fs -> SplitSepByNext st fs

step gst (SplitSepByInitFold1 st fs) = do
r <- step1 (adaptState gst) st
case r of
Yield x s -> return $ Skip $ SplitSepByCheck s x fs
Skip s -> return $ Skip (SplitSepByInitFold1 s fs)
Stop -> final fs >> return Stop

step _ (SplitSepByCheck st x fs) = do
if predicate x
Expand Down

0 comments on commit cde9fea

Please sign in to comment.