How could I go about getting put to work on the StateT monad while inside forM_?
loop :: Integer -> StateT World IO ()
loop passes = do
(scene, b1) <- get
forM_ [1..passes] $ \pass -> do
let b2 = foo b1 pass
-- other stuff --
put (scene, b2) -- this no longer puts into the StateT monad
Or is there a better approach all-together?
I think it works fine, for example:
running
evalStateT loop 0prints10like I’d expect.mapM_under the hood does this:Actually do the map, which for the above example returns a list
[StateT Integer IO ()]Do a right fold like:
foldr (>>) (return ()) listOfMappedValuesIt’s not clear what exactly your expecting but this would let you put things into the State from a
mapM_