@@ -28,6 +28,7 @@ module Streamly.Internal.Data.Parser.ParserD
28 -- First order parsers
28 -- First order parsers
29 -- * Accumulators
29 -- * Accumulators
30 , fromFold
30 , fromFold
31 , fromPure
32 , fromPure
32 , fromEffect
33 , fromEffect
@@ -297,6 +298,43 @@ fromFold (Fold fstep finitial fextract) = Parser step initial fextract
297 FL.Partial s1 -> Partial 0 s1
298 FL.Partial s1 -> Partial 0 s1
298 FL.Done b -> Done 0 b
299 FL.Done b -> Done 0 b
301+-- | Convert Maybe returning folds to error returning parsers.
305+{-# INLINE fromFoldMaybe #-}
306+fromFoldMaybe :: MonadThrow m => Fold m a (Maybe b) -> Parser m a b
307+fromFoldMaybe (Fold fstep finitial fextract) = Parser step initial extract
310+ errMsg = "Parse Error!"
316+ FL.Partial s1 -> IPartial s1
320+ Nothing -> IError errMsg
326+ FL.Partial s1 -> Partial 0 s1
330+ Nothing -> Error errMsg
336+ Nothing -> throwM $ ParseError errMsg
300-------------------------------------------------------------------------------
338-------------------------------------------------------------------------------
301-- Failing Parsers
339-- Failing Parsers
302-------------------------------------------------------------------------------
340-------------------------------------------------------------------------------