title: Scala using val as a counter
body: <p>I'm working on a scala task to accomplish this: </p>
  
  <p>The observeCounter function has one parameter f: a function that accepts (a reference to) a Counter instance but returns nothing.
  The observeCounter function should call f with (a reference to) an object (of a class extending Counter).
  Your class that extends Counter must keep track of the total number of times that increment/decrement have been called.
  I.e., if the increment method is called 3 times on an instance, and the decrement method is called 2 times on the same instance, then it should store 5  (somewhere other than the existing field n).
  observeCounter should call f, and then return the total number of times that increment/decrement were called on the instance by f.   </p>
  
  <pre><code>class myCounter extends Counter {
   val total = 0
   def increment () = {increment(); total = total + 1;}
   def decrement () = {decrement(); total = total + 1;}
   def get() : Int = total 
  }
  
  
  def observeCounter (f : Counter =&gt; Unit) : Int = {
   val o1 = new myCounter() 
   f(o1)
   o1.get()
  }
  </code></pre>
  
  <p>One of the requirements is to use val and not var. I have no clue how to accomplish that. Any suggestions?</p>