Actually it would probably be cleaner to write this code like this:
```
(0 until partitions.length).iterator.flatMap(i => collectPartition(i))
```
Since we're not returning a Stream anymore, but rather an iterator. You could also just make `collectPartition` take a Partition object and then do `partitions.iterator.flatMap(...)`.