unfoldM package:ihaskell
This is unfoldM from monad-loops. It repeatedly runs an IO action
until it return Nothing, and puts all the Justs in a list. If you find
yourself using more functionality from monad-loops, just add the
package dependency instead of copying more code from it.