title: Scala opening write to stdout or file
body: <p>Let's say I have a function</p>
  
  <pre><code>writeToFileOrStdout(fname: String = Nil) = { ... }
  </code></pre>
  
  <p>If the user passes a string value for fname, then I'd like to open a file with that name and write to it; otherwise, I'd like to print to stdout. I could always just write an if statement to take care of this, but how would I write a case statement on fname and open the correct corresponding outputStream?</p>
  
  <pre><code>    val outStream = fname match {
        case Nil =&gt; ???
        case _   =&gt; new java.io.FileOutputStream(new java.io.File(fname))
      }
      outStream.write( ... )
  </code></pre>
  
  <p>Thanks!</p>