Calculate profile in Scala with foldLeft