Writing more general group-by reductions