title: How to flatmap nested lists in spark
body: <p>I have a RDD in spark which looks like this - </p>
  
  <pre><code>[Foo1, Bar[bar1,bar2]]
  </code></pre>
  
  <p>The Bar object has a getList method which may return the lists [bar11,bar12,bar13] and [bar21, bar22] respectively. I want the output to look like this - </p>
  
  <pre><code>[Foo1, [bar11, bar12, bar13, bar21, bar22]]
  </code></pre>
  
  <p>The approach that I am able to think of is something like this - </p>
  
  <pre><code>my_rdd.map(x =&gt; (x._1,x._2.getList))
      .flatmap{
          case(x,y) =&gt; y.map(x, _)
      }
  </code></pre>
  
  <p>The first map operation is returning me Foo1 and all the lists. However I am not able to flatten them beyond that.</p>