title: How to update a variable that is Option[A] based on new values
body: <p>Sorry for what appears to be a Scala newbie question but lets say I have a variable "minVal" that is Option[Int] that is in a class. I need to update that variable if I get a new observation that is larger. Actually, I have many other variables -- e.g., maxVal, minDates, maxDates, minLength, maxLength, etc. Below is just a small snippet. So in addition to Option[Int], I also have Option[Date], Option[String] that have a similar update requirement.  </p>
  
  <p>I was wondering if there is a better way to calculate a min. </p>
  
  <pre><code>var minVal:Option[Int] = None
  def registerObs(x: Option[Int]) = {
    if (x.isDefined) 
      minVal match {
        case None                   =&gt; minVal = x
        case Some(mv) if mv &lt; x.get =&gt; minVal = x
        case _ =&gt; 
      } 
  }
  </code></pre>
  
  <p>Thanks in advance. </p>