missing do-all from Enumerator

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
concatMapAccumFinal :: Monad m
                    => (s -> ao -> Either ([ao], [ai]) (s, [ai]))
                    -> (s -> [ai])
                    -> s
                    -> Enumeratee ao ai m b
concatMapAccumFinal _nxt _fin _s y@(Yield _ _ ) = return y
concatMapAccumFinal _nxt _fin _s (Error e )     = throwError e
concatMapAccumFinal nxt fin s st@(Continue k) = continue $ step s k
  where
  
  step s k EOF = case fin s of
    [] -> yield (Continue k) EOF
    ai -> k (Chunks ai) >>== checkDoneEx EOF (\k' -> yield (Continue k') EOF)
    
  step s k (Chunks xs) = loop s k xs
  
  loop s k [] = continue (step s k)
  loop s k (x:xs) = case nxt s x of
    Right (s', ai) ->
      k (Chunks ai) >>== checkDoneEx (Chunks xs) (\k' -> loop s' k' xs)
    Left (x', ai) ->
      let xs' = x' ++ xs
      in k (Chunks ai) >>==
              checkDoneEx (Chunks xs') (\k' -> yield (Continue k') (Chunks xs'))