@@ -817,6 +817,11 @@ takeEQ n (Fold fstep finitial fextract) = Parser step initial extract
817 $ "takeEQ: Expecting exactly " ++ show n
817 $ "takeEQ: Expecting exactly " ++ show n
818 ++ " elements, input terminated on " ++ show (i - 1)
818 ++ " elements, input terminated on " ++ show (i - 1)
820+{-# ANN type TakeGEState Fuse #-}
820-- | Take at least @n@ input elements, but can collect more.
825-- | Take at least @n@ input elements, but can collect more.
822-- * Stops - when the collecting fold stops.
827-- * Stops - when the collecting fold stops.
@@ -837,48 +842,51 @@ takeGE n (Fold fstep finitial fextract) = Parser step initial extract
842 initial = do
845 initial = do
843 res <- finitial
846 res <- finitial
844− return $ case res of
847+ case res of
845− FL.Partial s -> IPartial $ Tuple' 0 s
848+ FL.Partial s ->
850+ then return $ IPartial $ TakeGELT 1 s
851+ else return $ IPartial $ TakeGEGE s
846− FL.Done b ->
852+ FL.Done b -> return $
847− if cnt == 0
853+ if n > 0
849− else IError
854+ then IError
850− $ "takeGE: Expecting at least " ++ show cnt
855+ $ "takeGE: Expecting at least " ++ show n
851 ++ " elements, fold terminated without"
856 ++ " elements, fold terminated without"
852 ++ " consuming any elements"
857 ++ " consuming any elements"
854− step (Tuple' i r) a
860+ step (TakeGELT i1 r) a = do
856− res <- fstep r a
861+ res <- fstep r a
858 $ case res of
865 $ case res of
859− FL.Partial s -> Continue 0 $ Tuple' i1 s
866+ FL.Partial s -> Continue 0 $ TakeGELT (i1 + 1) s
860 FL.Done _ ->
867 FL.Done _ ->
862− $ "takeGE: Expecting at least " ++ show cnt
869+ $ "takeGE: Expecting at least " ++ show n
863 ++ " elements, fold terminated on " ++ show i1
870 ++ " elements, fold terminated on " ++ show i1
864− | otherwise = do
871+ else
865− res <- fstep r a
872+ -- assert (n <= i1)
867 $ case res of
874 $ case res of
868− FL.Partial s -> Partial 0 $ Tuple' i1 s
875+ FL.Partial s -> Partial 0 $ TakeGEGE s
869 FL.Done b -> Done 0 b
876 FL.Done b -> Done 0 b
877+ step (TakeGEGE r) a = do
881+ FL.Partial s -> Partial 0 $ TakeGEGE s
882+ FL.Done b -> Done 0 b
875− extract (Tuple' i r)
884+ extract (TakeGELT i _) =
876− | i >= cnt = fmap (Done 0) $ fextract r
880− $ "takeGE: Expecting at least " ++ show cnt
887+ $ "takeGE: Expecting at least " ++ show n
881− ++ " elements, input terminated on " ++ show i
888+ ++ " elements, input terminated on " ++ show (i - 1)
889+ extract (TakeGEGE r) = fmap (Done 0) $ fextract r
883-------------------------------------------------------------------------------
891-------------------------------------------------------------------------------
884-- Conditional splitting
892-- Conditional splitting