on master help sign in
Add comments about modular impl of take ops
9d69c66Harendra Kumar
core/src/Streamly/Internal/Data/Parser/ParserD.hs+17−1
@@ -119,7 +119,12 @@ module Streamly.Internal.Data.Parser.ParserD
119 , takeWhile1
119 , takeWhile1
120 , dropWhile
120 , dropWhile
121
121
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.
123 , takeEndBy
128 , takeEndBy
124 , takeEndBy_
129 , takeEndBy_
125 , takeEndByEsc
130 , takeEndByEsc
@@ -944,6 +949,17 @@ takeWhile predicate (Fold fstep finitial fextract) =
944
949
945 extract s = fmap (Done 0) (fextract s)
950 extract s = fmap (Done 0) (fextract s)
946
951
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+
947-- | Like 'takeWhile' but takes at least one element otherwise fails.
963-- | Like 'takeWhile' but takes at least one element otherwise fails.
948--
964--
949-- >>> takeWhile1 cond p = Parser.takeWhileP cond (Parser.takeBetween 1 maxBound p)
965-- >>> takeWhile1 cond p = Parser.takeWhileP cond (Parser.takeBetween 1 maxBound p)