[SPARK-4964] add foreachPartitionWithIndex, to avoid doing equivalent map + empty foreach boilerplate