Scala - How to avoid a var here : <p>I wonder if anybody knows how to avoid the var in the following pseudocode:</p>

<pre><code>var cnt = theConstant
val theSequence = theMap.flapMap{case (theSet, theList) =&gt;
  if (theSet.isEmpty) {
    // do something here with theList and return a sequence
  } else {
    cnt += 1
    // do something here with cnt and theList and return a sequence
  }}
</code></pre>
