on master help sign in
Fix takeGE
commit927e42f84940e7d5c546431010770ceaaa4dd558 authorHarendra Kumar <harendra@composewell.com> dateThu 10 Dec 2020, 14:02 (6 years ago) parente27494a
1 file changed+16−10
src/Streamly/Internal/Data/Parser/ParserD.hs+16−10
src/Streamly/Internal/Data/Parser/ParserD.hs+16−10
@@ -369,27 +369,33 @@ takeGE cnt (Fold fstep finitial fextract) = Parser step initial extract
369369 initial = Tuple' 0 <$> finitial
370370
371371 step (Tuple' i r) a
372− | i < n = do
372+ | i1 < n = do
373373 res <- fstep r a
374374 return
375375 $ case res of
376− FL.Partial s -> Continue 0 $ Tuple' (i + 1) s
377− FL.Done _ -> Error $ err (i + 1)
376+ FL.Partial s -> Continue 0 $ Tuple' i1 s
377+ FL.Done _ ->
378+ Error
379+ $ "takeGE: the collecting fold terminated after "
380+ ++ "consuming " ++ show i1 ++ " elements"
378381 | otherwise = do
379382 res <- fstep r a
380383 return
381384 $ case res of
382− FL.Partial s -> Partial 0 $ Tuple' (i + 1) s
385+ FL.Partial s -> Partial 0 $ Tuple' i1 s
383386 FL.Done b -> Done 0 b
384387
385− extract (Tuple' i b)
386− | i >= n = fextract b
387− | otherwise = throwM $ ParseError $ err i
388+ where
388389
389− err i =
390− "takeGE: Expecting at least "
391− ++ show n ++ " elements, got only " ++ show i
390+ i1 = i + 1
392391
392+ extract (Tuple' i r)
393+ | i >= n = fextract r
394+ | otherwise =
395+ throwM
396+ $ ParseError
397+ $ "takeGE: Expecting at least "
398+ ++ show n ++ " elements, got " ++ show i
393399
394400-- | See 'Streamly.Internal.Data.Parser.takeWhile'.
395401--