@@ -578,6 +578,8 @@ takeGE n = D.toParserK . D.takeGE n
578-- $takeWhile
578-- $takeWhile
579-- Note: This is called @takeWhileP@ and @munch@ in some parser libraries.
579-- Note: This is called @takeWhileP@ and @munch@ in some parser libraries.
581+-- XXX We should perhaps use only takeWhileP and rename it to takeWhile.
581-- | Like 'takeWhile' but uses a 'Parser' instead of a 'Fold' to collect the
583-- | Like 'takeWhile' but uses a 'Parser' instead of a 'Fold' to collect the
582-- input. The combinator stops when the condition fails or if the collecting
584-- input. The combinator stops when the condition fails or if the collecting
583-- parser stops.
585-- parser stops.
@@ -585,19 +587,16 @@ takeGE n = D.toParserK . D.takeGE n
585-- This is a generalized version of takeWhile, for example 'takeWhile1' can be
587-- This is a generalized version of takeWhile, for example 'takeWhile1' can be
586-- implemented in terms of this:
588-- implemented in terms of this:
589−-- takeWhile1 cond p = takeWhile cond (takeBetween 1 maxBound p)
590+-- >>> takeWhile1 cond p = takeWhile cond (takeBetween 1 maxBound p)
592-- Stops: when the condition fails or the collecting parser stops.
592-- Stops: when the condition fails or the collecting parser stops.
593-- Fails: when the collecting parser fails.
593-- Fails: when the collecting parser fails.
595−-- /Unimplemented/
595+-- /Pre-release/
597{-# INLINE takeWhileP #-}
597{-# INLINE takeWhileP #-}
598−takeWhileP :: -- MonadCatch m =>
599− (a -> Bool) -> Parser m a b -> Parser m a b
598+takeWhileP :: MonadCatch m => (a -> Bool) -> Parser m a b -> Parser m a b
600−takeWhileP _cond = undefined -- D.toParserK . D.takeWhileP cond
599+takeWhileP cond p = D.toParserK $ D.takeWhileP cond (D.fromParserK p)
602-- | Collect stream elements until an element fails the predicate. The element
601-- | Collect stream elements until an element fails the predicate. The element
603-- on which the predicate fails is returned back to the input stream.
602-- on which the predicate fails is returned back to the input stream.
@@ -608,6 +607,8 @@ takeWhileP _cond = undefined -- D.toParserK . D.takeWhileP cond
608-- >>> Stream.parse (Parser.takeWhile (== 0) Fold.toList) $ Stream.fromList [0,0,1,0,1]
607-- >>> Stream.parse (Parser.takeWhile (== 0) Fold.toList) $ Stream.fromList [0,0,1,0,1]
610+-- >>> takeWhile cond f = Parser.takeWhileP cond (Parser.fromFold f)
611-- We can implement a @breakOn@ using 'takeWhile':
612-- We can implement a @breakOn@ using 'takeWhile':
@@ -619,20 +620,26 @@ takeWhileP _cond = undefined -- D.toParserK . D.takeWhileP cond
619{-# INLINE takeWhile #-}
620{-# INLINE takeWhile #-}
620takeWhile :: MonadCatch m => (a -> Bool) -> Fold m a b -> Parser m a b
621takeWhile :: MonadCatch m => (a -> Bool) -> Fold m a b -> Parser m a b
621takeWhile cond = D.toParserK . D.takeWhile cond
622takeWhile cond = D.toParserK . D.takeWhile cond
623+-- takeWhile cond f = takeWhileP cond (fromFold f)
623-- | Like 'takeWhile' but takes at least one element otherwise fails.
625-- | Like 'takeWhile' but takes at least one element otherwise fails.
627+-- >>> takeWhile1 cond p = Parser.takeWhileP cond (Parser.takeBetween 1 maxBound p)
625-- /Pre-release/
629-- /Pre-release/
627{-# INLINE takeWhile1 #-}
631{-# INLINE takeWhile1 #-}
628takeWhile1 :: MonadCatch m => (a -> Bool) -> Fold m a b -> Parser m a b
632takeWhile1 :: MonadCatch m => (a -> Bool) -> Fold m a b -> Parser m a b
629takeWhile1 cond = D.toParserK . D.takeWhile1 cond
633takeWhile1 cond = D.toParserK . D.takeWhile1 cond
634+-- takeWhile1 cond f = takeWhileP cond (takeBetween 1 maxBound f)
631-- | Drain the input as long as the predicate succeeds, running the effects and
636-- | Drain the input as long as the predicate succeeds, running the effects and
632-- discarding the results.
637-- discarding the results.
634-- This is also called @skipWhile@ in some parsing libraries.
639-- This is also called @skipWhile@ in some parsing libraries.
641+-- >>> dropWhile p = Parser.takeWhile p Fold.drain
636-- /Pre-release/
643-- /Pre-release/
638{-# INLINE dropWhile #-}
645{-# INLINE dropWhile #-}