title: How to use RDD.flatMap?
body: <p>I have a text file with lines that contain <code>userid</code> and <code>rid</code> separated by <code>|</code> (pipe). <code>rid</code> values correspond to many labels on another file.</p>
  
  <p>How can I use <code>flatMap</code> to implement a method as follows:</p>
  
  <pre><code>xRdd  = sc.textFile("file.txt").flatMap { line =&gt; 
    val (userid,rid) = line.split("\\|")
    val labelsArr = getLabels(rid)
    labelsArr.foreach{ i =&gt;
      ((userid, i), 1)
    }
  }
  </code></pre>
  
  <p>At compile time, I get an error:</p>
  
  <blockquote>
    <p>type mismatch; found : Unit required: TraversableOnce[?]</p>
  </blockquote>