Generalized repeatUntilEmpty to repeatWhileBlock