unfoldM package:monad-loops

The supplied Maybe expression will be repeatedly called until it returns Nothing. All values returned are collected into a list.
The supplied Maybe expression will be repeatedly called until it returns Nothing. All values returned are collected into an arbitrary MonadPlus thing.
The supplied Maybe expression will be repeatedly called until it returns Nothing. All values returned are discarded.