title: udf spark Scala return case class
body: <pre><code>import org.apache.spark.sql.functions._
  
  case class oneClass(a : Int , b: String , c :string)
  
  val doSomthing = udf ((t1 : Seq[String], str : String , values : t2 Seq[String])
      =&gt; {
      val pos = t1.indexOf(str)
      if (pos &gt;= 0) oneClass(pos, str,t2(pos))
      //if no control of pos possible return -1 ===&gt; indexoutofboundsexception
      //if control the udf return Any then when I use it ===&gt; Exception
      }
  )
  </code></pre>
  
  <p>How I can return case class only when pos >= 0 and all the time return case class ??</p>