title: scala foreach loop return list
body: <p>I am a newbie to scala (and functional programming, basically). I am trying to loop over a list of rows (can think as strings), where each string will be passed to a different scala method, where I am doing some manipulation on the input string and then return a string to the for-loop.</p>
  
  <p>below is not the working code, but this is what I am expecting to work. </p>
  
  <pre><code>     val input_list = spark.read
            .format("com.crealytics.spark.excel")
            .option("sheetName" , "SchemaInfo")
            .option("useHeader", "true")
            .schema(profilerSchema)
            .load(path)  // this is spark dataframe, which has rows.
  
   val columnNames : List[String] = new List("Hello" , "world");
  
           var outputList = new ListBuffer[String]();
  
          // Here i am iterating the input_list where i pass each ele to getString() method where  
          // it returns the final string which i want to add to outputList. 
  
           input_list.foreach(i =&gt; {
                  val res: String = getString(row, columnNames)
                   outputList += res;
                 }));
  
  
           def getString(row: Row, schemaNames: List[String]) : String  = {
  
          // some implementation where it returns a string.
          }
  </code></pre>
  
  <p>Below is the error message I am getting (discard the line number. its getting at the foreach loop.).</p>
  
  <pre><code>Error:(57, 14) overloaded method value foreach with alternatives:
    (func: org.apache.spark.api.java.function.ForeachFunction[org.apache.spark.sql.Row])Unit &lt;and&gt;
    (f: org.apache.spark.sql.Row =&gt; Unit)Unit
   cannot be applied to (org.apache.spark.sql.Row =&gt; scala.collection.mutable.ListBuffer[String])
      excel_df.foreach{row =&gt; (jsonStrList += convertRowToJSON(row, columnNames))};
  </code></pre>
  
  <p>I am having a hard time writing the logic. any help is really appreciated.</p>