ekmett / machines

Networks of composable stream transducers
Other
340 stars 46 forks source link

Stricter `foldlT`? #114

Open pkamenarsky opened 2 years ago

pkamenarsky commented 2 years ago

foldlT still seems to leak some space, and strictly applying o to f b seems to solve this (e.g. f b $! o). I can submit a PR if desired.

foldlT :: Monad m => (b -> o -> b) -> b -> M.MachineT m k o -> m b
foldlT f = go
  where
    go !b m = do
      step <- M.runMachineT m
      case step of
        M.Stop -> return b
        M.Yield o m' -> go (f b $! o) m'
        M.Await _ _ m' -> go b m'