Implement partitionWithKey and partition.