Try it like this style:

    val partitions: Array[Partition] = rdd.partitions
      .zipWithIndex.filter(s => partitionFilterFunc(s._2))
      .map { case(split, idx) => new PartitionPruningRDDPartition(idx, split) : Partition }