title: In Scala, how do I keep track of running totals without using var?
body: <p>For example, suppose I wish to read in fat, carbs and protein and wish to print the running total of each variable.  An imperative style would look like the following:</p>
  
  <pre><code>var totalFat = 0.0
  var totalCarbs = 0.0
  var totalProtein = 0.0
  var lineNumber = 0
  
  for (lineData &lt;- allData) {
      totalFat += lineData...
      totalCarbs += lineData...
      totalProtein += lineData...
      lineNumber += 1
  
      printCSV(lineNumber, totalFat, totalCarbs, totalProtein)
  
  }
  </code></pre>
  
  <p>How would I write the above using only vals?</p>