Skip to content

Instantly share code, notes, and snippets.

@blippy
Created December 8, 2015 22:33
Show Gist options
  • Save blippy/4a36f5342d11230ad0b5 to your computer and use it in GitHub Desktop.
Save blippy/4a36f5342d11230ad0b5 to your computer and use it in GitHub Desktop.
Looping and collecting using monads
loopCollect state0 xs func = fst $ runState (forM xs func) state0
-- result is ["hello", " ", "world"]
eg = loopCollect "hello world" [5, 1, 5]
(\i -> do
str <- get
let (h, t) = splitAt i str
put t
return h)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment