Implement partitionWithKey.