Instead of a for loop, if you use a map, you can get rid of the ArrayBuffer

    packer.getPartitions.zipWithIndex.map { case(pg, i) =>
      ...
    }.toArray