title: How can assign different return types to a function in Scala?
body: <p>I am trying to write a function which should return different pairs depending on the input. I have override the "+ - / *" in Scala for my specific use. Each one ( +, -,* ,/) has three implementations based on the input. I have RDD and Float as inputs so it can be a + between RDD and RDD, or Float and RDD, or Float and Float and so on. </p>
  
  <p>Now I am having a parser which reads expression from input like : RDD+1 , parse it and create postfix to make calculations easier like : RDD1+ and then I want to do a calculation using my implemented + . with the help of <a href="https://github.com/bitwalker/RPNCalculator/blob/master/src/main/scala/App.scala" rel="nofollow">this algorithm</a> I am trying to change it in a way to make it performing a calculation based on my input expression. For instance it contains:</p>
  
  <pre><code> var lastOp: (Float, Float) =&gt; Float = add
  </code></pre>
  
  <p>How can I change this: <code>(Float, Float) =&gt; Float</code> to something that will accept <code>(RDD, Float)|(RDD, RDD) |(Float, Float) =&gt; RDD = add</code> // my implementation of add ???</p>
  
  <p>Edition:</p>
  
  <p>I added this part with the help of two answers below:
  Ok I wrote this :  </p>
  
  <pre><code>     def lastop:(Either[RDD[(Int,Array[Float])], Float], Either[RDD[(Int,Array[Float])], Float]) =&gt; RDD[(Int,Array[Float])] = sv.+
  </code></pre>
  
  <p>in which sv is an instance from my other class that I have been override + in that but in two different ways so now I ma getting an error which I guess is because compiler gets confused about which implementation to use this is the   </p>
  
  <pre><code>       error:  type mismatch;
         [error]  found   : (that: org.apache.spark.rdd.RDD[(Int, Array[Float])])org.apache.spark.rdd.RDD[(Int, Array[Float])] &lt;and&gt; (that: Float)org.apache.spark.rdd.RDD[(Int, Array[Float])]
         [error]  required: (Either[org.apache.spark.rdd.RDD[(Int, Array[Float])],Float], Either[org.apache.spark.rdd.RDD[(Int, Array[Float])],Float]) =&gt; org.apache.spark.rdd.RDD[(Int, Array[Float])]
  </code></pre>
  
  <p>Note: what it says it found are two different implementations for "+"</p>