Implement group-by

Note that since 02ccc4d727a9297f14219549208757c6e0efce2a, the val-fn
variant of groupBy is unimplemented so for now an exception is thrown if
it's used.