title: scala pattern matching with either
body: <p>I want a function <code>readFile</code> that takes as input a variable <code>file</code>. File can be both a <code>string</code> or a <code>java.io.File</code>.  Suppose to have a function <code>readJavaFile</code> that accept a <code>java.io.File</code> as input. </p>
  
  <p>I want to do something like:</p>
  
  <pre><code>def readFile(file:Either[String, File]) = {
     file match {
       case s:String =&gt; readJavaFile(new File(s))
       case s:File =&gt; readJavaFile(s)
     }
  }
  </code></pre>
  
  <p>What is the right way to implement this? I saw similar questions on SO but they were referring to more complex situations. </p>
  
  <p>EDIT:
  I am afraid that <code>Either</code> is not the way to follow. I want to be able to call the function as :
  <code>readFile(s)</code> where <code>s</code> is a string or <code>readFile(f)</code> where <code>f</code> is a <code>File</code></p>
  
  <p>EDIT: 
  This is my real code:</p>
  
  <pre><code>def csvread(file: File,
               separator: Char=',',
               quote: Char='"',
               escape: Char='\\',
               skipLines: Int = 0): DenseMatrix[Double] = {
      val input = new FileReader(file)
      var mat = CSVReader.read(input, separator, quote, escape, skipLines)
      mat = mat.takeWhile(line =&gt; line.length != 0 &amp;&amp; line.head.nonEmpty) // empty lines at the end
      input.close()
      if(mat.length == 0) {
        DenseMatrix.zeros[Double](0,0)
      } else {
        DenseMatrix.tabulate(mat.length,mat.head.length)((i,j)=&gt;mat(i)(j).toDouble)
      }
    }
  
    def csvread(file: String,
                separator: Char=',',
                quote: Char='"',
                escape: Char='\\',
                skipLines: Int = 0): DenseMatrix[Double] = csvread(new File(file), separator, quote, escape, skipLines)
  </code></pre>
  
  <p>And I want to call it as:</p>
  
  <pre><code>package breeze.linalg
  
  /**
    * Created by donbeo on 07/02/16.
    */
  
  import org.scalatest._
  import org.scalatest.junit._
  import org.scalatest.prop._
  import org.junit.runner.RunWith
  import breeze.linalg.csvread
  import java.io.File
  
  @RunWith(classOf[JUnitRunner])
  class ReadCsvTest extends FunSuite with Checkers{
  
    test("Try readcsv") {
      val f = csvread(new File("/Users/donbeo/Documents/datasets/glass.csv"))
      val v = csvread("/Users/donbeo/Documents/datasets/glass.csv")
  
    }
  
  }
  </code></pre>
  
  <p>but I receive and error:</p>
  
  <pre><code>Error:(41, 16) in package object linalg, multiple overloaded alternatives of method csvread define default arguments.
  package object linalg {
                 ^
  </code></pre>