This one is trickier. It would work efficiently like
```
distances groupBy { case (pid, _) => pid } reduce( (x, y) => { if (x._2.distance < y._2.distance) x else y } )
```
but it is not quite as nice. The minBy function on iterators is very convenient here. However, the reduce that has an iterator is not combinable. Even if we re-introduced the combinable version with the iterator, the system could not figure out that this is a function that can be applied on pairs and hence never use running aggregates (hash based) but only sorted aggregates.

Also not totally straightforward is:
```
distances groupBy { case (pid, _) => pid } reduce ( Seq(_, _).minBy(_._2.distance)  ) 
```
but it creates the undesired sequence objects.

We should solve that by introducing built-in aggregate functions that take key selectors. Something like 
```
distances groupBy { case (pid, _) => pid } aggregate( MIN, { _._2.distance } ) 
```
We can also translate this into very efficient code, as we can use the analyzed selector function to directly go into the runtime object layout, skipping the user code altogether.