@@ -67,6 +67,7 @@ module Streamly.Internal.Data.Parser
67 -- Grab a sequence of input elements by inspecting them
67 -- Grab a sequence of input elements by inspecting them
68 , takeWhile
68 , takeWhile
69 -- , takeWhileBetween
69 -- , takeWhileBetween
71 , sepByMax
72 , sepByMax
72 -- , sepByBetween
73 -- , sepByBetween
@@ -400,6 +401,38 @@ takeWhile predicate (Fold fstep finitial fextract) =
400 then Yield 0 <$> fstep s a
401 then Yield 0 <$> fstep s a
401 else Stop 1 <$> fextract s
402 else Stop 1 <$> fextract s
404+-- | Like 'takeWhile' but takes at least one element otherwise fails.
408+{-# INLINE takeWhile1 #-}
409+takeWhile1 :: MonadThrow m => (a -> Bool) -> Fold m a b -> Parser m a b
410+takeWhile1 predicate (Fold fstep finitial fextract) =
411+ Parser step initial extract
415+ initial = return Nothing
422+ return $ Yield 0 (Just r)
423+ else return $ Error "takeWhile1: empty"
428+ return $ Yield 0 (Just r)
433+ extract Nothing = throwM $ ParseError "takeWhile1: end of input"
434+ extract (Just s) = fextract s
403-- | Collect stream elements until an element succeeds the predicate. Drop the
436-- | Collect stream elements until an element succeeds the predicate. Drop the
404-- element on which the predicate succeeded. The succeeding element is treated
437-- element on which the predicate succeeded. The succeeding element is treated
405-- as an infix separator which is dropped from the output.
438-- as an infix separator which is dropped from the output.