on master help sign in
Add comments about modular impl of take ops
commit9d69c6691970d7ab18c5d03917cfd57cd412b5aa authorHarendra Kumar <harendra@composewell.com> dateSun 19 Feb 2023, 17:01 (4 years ago) parentd616258
1 file changed+17−1
core/src/Streamly/Internal/Data/Parser/ParserD.hs+17−1
core/src/Streamly/Internal/Data/Parser/ParserD.hs+17−1
@@ -119,7 +119,12 @@ module Streamly.Internal.Data.Parser.ParserD
119119 , takeWhile1
120120 , dropWhile
121121
122− -- ** Separators
122+ -- ** Single Element Separators
123+ -- | Separator could be in prefix postion ('takeStartBy'), or suffix
124+ -- position ('takeEndBy').
125+
126+ -- These can be implemented modularly with refolds, using takeWhile and
127+ -- satisfy.
123128 , takeEndBy
124129 , takeEndBy_
125130 , takeEndByEsc
@@ -944,6 +949,17 @@ takeWhile predicate (Fold fstep finitial fextract) =
944949
945950 extract s = fmap (Done 0) (fextract s)
946951
952+{-
953+-- XXX This may not be composable because of the b argument. We can instead
954+-- return a "Reparse b a m b" so that those can be composed.
955+{-# INLINE takeWhile1X #-}
956+takeWhile1 :: Monad m => b -> (a -> Bool) -> Refold m b a b -> Parser a m b
957+-- We can implement this using satisfy and takeWhile. We can use "satisfy
958+-- p", fold the result with the refold and then use the "takeWhile p" and
959+-- fold that using the refold.
960+takeWhile1 acc cond f = undefined
961+-}
962+
947963-- | Like 'takeWhile' but takes at least one element otherwise fails.
948964--
949965-- >>> takeWhile1 cond p = Parser.takeWhileP cond (Parser.takeBetween 1 maxBound p)