title: Scala - merge a list to map
body: <p>I need to merge a list into a set from an <code>RDD</code>, but I got stuck doing it in Scala:</p>
  
  <pre><code>var accounts = set("name" -&gt; "", "id" -&gt; 0, ....)
  
  //Split the RDD into lines and split each line by `|` to get the values
  stream.foreachRDD {_.map(_._2).flatMap(_.split("|")).foreach(f =&gt; /*merge here ?*/)}
  </code></pre>
  
  <p>How do I associate the values with my account sets?</p>
  
  <p>For example, assume a RDD loaded from a CSV (I made up this data)</p>
  
  <pre><code> Donald|Trump|US|Election|March|Spring|Rubio|Ted Cruz|Ben Carson|Primary|Winner|...
   Donald|Trump|US|Election|March|Spring|Rubio|Ted Cruz|Ben Carson|Primary|Winner|...
   Donald|Trump|US|Election|March|Spring|Rubio|Ted Cruz|Ben Carson|Primary|Winner|...
   Donald|Trump|US|Election|March|Spring|Rubio|Ted Cruz|Ben Carson|Primary|Winner|...
   Donald|Trump|US|Election|March|Spring|Rubio|Ted Cruz|Ben Carson|Primary|Winner|...
   Donald|Trump|US|Election|March|Spring|Rubio|Ted Cruz|Ben Carson|Primary|Winner|...
   Donald|Trump|US|Election|March|Spring|Rubio|Ted Cruz|Ben Carson|Primary|Winner|...
   ...
  </code></pre>
  
  <p>The RDD has up to 300 columns/fields.</p>
  
  <p>My main objective is to convert it to some json but I need to associate each value to a key by loading it up to map or class.</p>
  
  <pre><code>var election = Map ("firstname" -&gt; "Donald",
  "lastname" -&gt; "Trump",
  "country" -&gt; "US",
  "event" -&gt; "Election",
  "period" -&gt; "March"
  "var1" -&gt; "Spring",
   ....
  "varN" -&gt; "...")
  </code></pre>