title: Extract elements of lists in an RDD
body: <h2>What I want to achieve</h2>
  
  <p>I'm working with Spark and Scala. I have two Pair RDDs.</p>
  
  <pre><code>rdd1 : RDD[(String, List[String])]
  rdd2 : RDD[(String, List[String])]
  </code></pre>
  
  <p>Both RDDs are joined on their first value.</p>
  
  <pre><code>val joinedRdd = rdd1.join(rdd2)
  </code></pre>
  
  <p>So the resulting RDD is of type <code>RDD[(String, (List[String], List[String]))]</code>. I want to map this RDD and extract the elements of both lists, so that the resulting RDD contains just these elements of the two lists.</p>
  
  <hr>
  
  <h2>Example</h2>
  
  <pre><code>rdd1 (id, List(a, b))
  rdd2 (id, List(d, e, f))
  wantedResult (a, b, d, e, f)
  </code></pre>
  
  <hr>
  
  <h2>Naive approach</h2>
  
  <p>My naive approach would be to adress each element directly with <code>(i)</code>, like below:</p>
  
  <pre><code>val rdd = rdd1.join(rdd2)
      .map({ case (id, lists) =&gt; 
          (lists._1(0), lists._1(1), lists._2(0), lists._2(2), lists._2(3)) })
  
  /* results in RDD[(String, String, String, String, String)] */
  </code></pre>
  
  <p>Is there a way to get the elements of each list, without adressing each individually? Something like "<code>lists._1.extractAll</code>". Is there a way to use <code>flatMap</code> to achieve what I'm trying to achieve?</p>