Does this need to be a builder? TreeSet has a companion object that you could probably use instead. If you do that, then the kmerGraph.allPaths.foreach can turn into a map.