title: Composing partial functions in Scala
body: <p>I have two partial functions <code>f1</code> and <code>f2</code> which I want to compose into a new partial function <code>f</code> so that <code>f.isDefinedAt(x)</code> iff <code>f1.isDefinedAt(x) || f2.isDefinedAt(x)</code>. I mean </p>
  
  <pre><code>        --
         | f1(x) iff f1.isDefinedAt(x)  
         |
  f(x) = |
         |
         | f2(x) iff  !f1.isDefinedAt(x) &amp;&amp; f2.isDefinedAt(x)  
          --
  </code></pre>
  
  <p>Is there a way to compose <code>f1</code> and <code>f2</code> that way?</p>