Given that Spark ensures continuous index space, why not just 

```
require(partitions.forall(p => p < rdd.partitions.size && p>=0), "...")

```