on master help sign in
Fix takeGE
927e42fHarendra Kumar
src/Streamly/Internal/Data/Parser/ParserD.hs+16−10
@@ -369,27 +369,33 @@ takeGE cnt (Fold fstep finitial fextract) = Parser step initial extract
369 initial = Tuple' 0 <$> finitial
369 initial = Tuple' 0 <$> finitial
370
370
371 step (Tuple' i r) a
371 step (Tuple' i r) a
372− | i < n = do
372+ | i1 < n = do
373 res <- fstep r a
373 res <- fstep r a
374 return
374 return
375 $ case res of
375 $ case res of
376− FL.Partial s -> Continue 0 $ Tuple' (i + 1) s
376+ FL.Partial s -> Continue 0 $ Tuple' i1 s
377− FL.Done _ -> Error $ err (i + 1)
377+ FL.Done _ ->
378+ Error
379+ $ "takeGE: the collecting fold terminated after "
380+ ++ "consuming " ++ show i1 ++ " elements"
378 | otherwise = do
381 | otherwise = do
379 res <- fstep r a
382 res <- fstep r a
380 return
383 return
381 $ case res of
384 $ case res of
382− FL.Partial s -> Partial 0 $ Tuple' (i + 1) s
385+ FL.Partial s -> Partial 0 $ Tuple' i1 s
383 FL.Done b -> Done 0 b
386 FL.Done b -> Done 0 b
384
387
385− extract (Tuple' i b)
388+ where
386− | i >= n = fextract b
387− | otherwise = throwM $ ParseError $ err i
388
389
389− err i =
390+ i1 = i + 1
390− "takeGE: Expecting at least "
391− ++ show n ++ " elements, got only " ++ show i
392
391
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
393
399
394-- | See 'Streamly.Internal.Data.Parser.takeWhile'.
400-- | See 'Streamly.Internal.Data.Parser.takeWhile'.
395--
401--