on master help sign in
Rename: ltakeWhile -> takeSepBy & drainWhile -> drainSepBy
0032f35adithyaov
src/Streamly/Internal/Data/Fold.hs+5−5
@@ -70,7 +70,7 @@ module Streamly.Internal.Data.Fold
70
70
71 -- ** Partial Folds
71 -- ** Partial Folds
72 , drainN
72 , drainN
73− , drainWhile
73+ , drainSepBy
74 -- , lastN
74 -- , lastN
75 -- , (!!)
75 -- , (!!)
76 -- , genericIndex
76 -- , genericIndex
@@ -131,7 +131,7 @@ module Streamly.Internal.Data.Fold
131 -- ** Trimming
131 -- ** Trimming
132 , ltake
132 , ltake
133 -- , lrunFor -- time
133 -- , lrunFor -- time
134− , ltakeWhile
134+ , takeSepBy
135 {-
135 {-
136 , ltakeWhileM
136 , ltakeWhileM
137 , ldrop
137 , ldrop
@@ -818,9 +818,9 @@ drainN n = ltake n drain
818
818
819-- | A fold that drains elements of its input as long as the predicate succeeds,
819-- | A fold that drains elements of its input as long as the predicate succeeds,
820-- running the effects and discarding the results.
820-- running the effects and discarding the results.
821−{-# INLINABLE drainWhile #-}
821+{-# INLINABLE drainSepBy #-}
822−drainWhile :: Monad m => (a -> Bool) -> Fold m a ()
822+drainSepBy :: Monad m => (a -> Bool) -> Fold m a ()
823−drainWhile p = ltakeWhile p drain
823+drainSepBy p = takeSepBy p drain
824
824
825------------------------------------------------------------------------------
825------------------------------------------------------------------------------
826-- To Elements
826-- To Elements
src/Streamly/Internal/Data/Fold/Types.hs+4−5
@@ -132,7 +132,7 @@ module Streamly.Internal.Data.Fold.Types
132 , lfilterM
132 , lfilterM
133 , lcatMaybes
133 , lcatMaybes
134 , ltake
134 , ltake
135− , ltakeWhile
135+ , takeSepBy
136
136
137 , teeWith
137 , teeWith
138 , teeWithFst
138 , teeWithFst
@@ -587,10 +587,9 @@ ltake n (Fold fstep finitial fextract) = Fold step initial extract
587-- | Takes elements from the input as long as the predicate succeeds.
587-- | Takes elements from the input as long as the predicate succeeds.
588--
588--
589-- @since 0.7.0
589-- @since 0.7.0
590−{-# INLINE ltakeWhile #-}
590+{-# INLINE takeSepBy #-}
591−ltakeWhile :: Monad m => (a -> Bool) -> Fold m a b -> Fold m a b
591+takeSepBy :: Monad m => (a -> Bool) -> Fold m a b -> Fold m a b
592−ltakeWhile predicate (Fold fstep finitial fextract) =
592+takeSepBy predicate (Fold fstep finitial fextract) = Fold step finitial fextract
593− Fold step finitial fextract
594
593
595 where
594 where
596
595
src/Streamly/Internal/Data/Parser/ParserD.hs+17−1
@@ -384,7 +384,23 @@ takeGE cnt (Fold fstep finitial fextract) = Parser step initial extract
384--
384--
385{-# INLINE takeWhile #-}
385{-# INLINE takeWhile #-}
386takeWhile :: Monad m => (a -> Bool) -> Fold m a b -> Parser m a b
386takeWhile :: Monad m => (a -> Bool) -> Fold m a b -> Parser m a b
387−takeWhile predicate fld = fromFold (FL.ltakeWhile predicate fld)
387+takeWhile predicate (Fold fstep finitial fextract) =
388+ Parser step initial fextract
389+
390+ where
391+
392+ initial = finitial
393+
394+ step s a =
395+ if predicate a
396+ then do
397+ fres <- fstep s a
398+ return
399+ $ case fres of
400+ FL.Partial s1 -> Partial 0 s1
401+ FL.Done b -> Done 0 b
402+ else Done 1 <$> fextract s
403+
388
404
389-- | See 'Streamly.Internal.Data.Parser.takeWhile1'.
405-- | See 'Streamly.Internal.Data.Parser.takeWhile1'.
390--
406--