title: How to combine Option values in Scala?
body: <p>I want to be able to apply an operation <code>f: (T,T) =&gt; T</code> to <code>Option[T]</code> values in Scala. I want the result to be <code>None</code> if any of the two values is <code>None</code>.</p>
  
  <p>More specifically, I want to know if there is a shorter way to do the following:</p>
  
  <pre><code>def opt_apply[T](f: (T,T) =&gt; T, x: Option[T], y: Option[T]): Option[T] = {
    (x,y) match {
      case (Some(u),Some(v)) =&gt; Some(f(u,v))
      case _ =&gt; None
    }
  }
  </code></pre>
  
  <p>I have tryied <code>(x zip y) map {case (u,v) =&gt; f(u,v)}</code> but the result is an <code>Iterator[T]</code> not an <code>Option[T]</code>.</p>