title: convert my below code into pure scala function
body: <pre><code> def buildDf(df:DataFrame,platformKey: PlatformKey):DataFrame=
      {
        var dataF = df
  
        val selectedColumns =  getSelectedColumns(platformKey)
  
        for((newStructCol,colAtribute) &lt;- selectedColumns._2 )
        {
          dataF = dataF.withColumn(newStructCol,struct(colAtribute:_*))
        }
        dataF
      }
  </code></pre>
  <p>How can i make this method to only use val . I am trying to add columns to my spark dataframe . is there a better way to code this and what issues I can face with my code?</p>