:: (a -> Bool) -> m a -> m [a] package:monad-loops

Repeatedly evaluates the second argument until the value satisfies the given predicate, and returns a list of all values that satisfied the predicate. Discards the final one (which failed the predicate).