Apply the same approach to groupBy.