title: Conditional type variable in Scala
body: <p>I am trying to define a variable 'type' in Scala after a conditional if-else. </p>
  
  <p>The purpose is to get a variable like <code>type In = xxx</code>. With that being able to instantiate a parametrized class or call a parametrized function. Given the definitions:</p>
  
  <pre><code>  class MyParamClass[T: TypeTag](context: String){...}
    def startStrean[T: TypeTag](context: String) = {...}
  </code></pre>
  
  <p>I want to create an instance of <code>MyParamClass[T](context = "my contentx")</code> where T depends on a configuration string. The configuration string, is something that the user can provide using an API.</p>
  
  <pre><code>  val conf = Option("Map[String, Any]")
  
    //get the data types from the context
    type In = conf match {
      case Some("Map[String, Int]") =&gt;      Map[String, Int]
      case Some("Map[String, Double]") =&gt;   Map[String, Double]
      case Some("List[Double]") =&gt;          List[Double]
      case Some("List[Int]") =&gt;             List[Int]
      case None =&gt;                          Map[String, Any]
    }
  </code></pre>
  
  <p><em>Note</em>: The previous code snippet does not compile.</p>
  
  <p>Then, to create the class or to execute the function:</p>
  
  <pre><code>val context = "my context"
  val pc = new MyParamClass[In](context)
  startStream[In](context)
  </code></pre>
  
  <p>Note that the Type <code>T</code> cannot be infer from the arguments types.</p>
  
  <p>Looking at <a href="https://docs.scala-lang.org/overviews/reflection/overview.html" rel="nofollow noreferrer">Scala reflection documentation</a> I see some ways. But, I am playing around with <code>tq</code>.</p>
  
  <p>The main problem I am encountering is how to define a type variable <code>type In</code> at runtime.</p>