title: Spark - Scala : Return multiple <key, value> after processing one line
body: <p>I have a dataset that looks like below - </p>
  
  <p>0 -- 1,2,4 <br>
  1 -- 0,4 <br>
  2 -- 0,4 <br>
  4 -- 2,1,0 <br></p>
  
  <p>I want to read each line and transform it to something that looks like below<br></p>
  
  <p>// for the line 0 -- 1,2,4 <br>
  (0,1) &lt;2,4> <br>
  (0,2) &lt;1,4> <br>
  (0,4) &lt;1,2> <br></p>
  
  <p>// for the line 1 -- 0,4 <br>
  (0,1) &lt;4> <br>
  (1,4) &lt;0> <br></p>
  
  <p>// smaller number appeears first in the pair always</p>
  
  <p>i.e., read each line separated on "--" delimiter. So I get 0 and 1,2,4 from line 1 of the dataset. After that, I want create pairs. For example, (0,1) which will be the key for the transformed map and its value should be 2,4.  </p>
  
  <p>Once this is done, I want to be able to group values by key </p>
  
  <p>For example (0,1) &lt;2,4> &lt;4></p>
  
  <p>and intersect them to get 4.</p>
  
  <p>Is it possible to do something like this? Is my approach right? </p>
  
  <p>I have written the below code so far-</p>
  
  <pre><code>var mapOperation = logData.map(x=&gt;x.split("\t")).filter(x =&gt; x.length == 2).map(x =&gt; (x(0),x(1)))
  // reading file and creating the map Example - key 0 value 1,2,4
  
  //from the first map, trying to create pairs
  var mapAgainstValue = mapOperation.map{
  line =&gt;
  val fromFriend = line._1
  val toFriendsList = line._2.split(",")
  (fromFriend -&gt; toFriendsList)
  }
  
  val newMap = mapAgainstValue.map{
  line =&gt;
  var key ="";
  for(userIds &lt;- line._2){
  key =line._1.concat(","+userIds);
  (key -&gt; line._2.toList)
  }
  
  }
  </code></pre>
  
  <p>The problem is I am not able to call groupByKey on newMap. I am assuming there is some issue with the way I have created the map?</p>
  
  <p>Appreciate any help.</p>
  
  <p>Thanks. </p>