title: More idiomatic (monadic?) way to express this Scala
body: <p>I have several blocks of code that follow this pattern:</p>
  
  <pre><code>// Dummy function defs.
  def result(i : Int, d : Double, b : Boolean) = {
      if (b) d else i
  }
  
  def fA(s : String) = {7}
  def fB(s : String, i : Int) = {1.0}
  def fC(s : String, i : Int, d : Double) = {true}
  
  // Actual code.
  def test(s : String) : Double = {
      try {
          val a = fA(s) 
          try {
              val b = fB(s, a)
              try {
                  val c = fC(s, a, b)
                  result(a, b, c)
              } catch {
                  case _ =&gt; result(a, b, false)
              }
  
          } catch {
              case _ =&gt; result(a, 0.0, false)
          }
      } catch {
          case _ =&gt; result(0, 0.0, false)
      }
  }
  </code></pre>
  
  <p>Where a, b, &amp; c are calculated in turn by the corresponding functions and then the values are passed to the result function. If at any stage an exception occurs then a default value is used in place of the remaining variables.</p>
  
  <p>Is there a more idiomatic way to express this code. It reminds me of Monads in that it's a series of chained computations which bail out immediately if any computation fails.</p>