pileups.groupBy (mapPileup)
      .flatMap (flatten)

is cleaner here.