Add GroupedSort.

This is a very rough version.