could this check be even simpler? E.g. why can't it just do something like:
```
partitions.foreach{ p => 
  require(p >= 0 && p < rdd.partitions.size, s"Invalid partition requested: $p")
}
```