Pull out this predicate loop into a helper function.