I think this function should be moved to subr.el. It's too general-purpose to be kept on minibuffer.el.