Add ruby-like group_by functionality.