title: Spark Group By Key to (Key,List) Pair
body: <p>I am trying to group some data by key where the value would be a list:</p>
  
  <p>Sample data:</p>
  
  <pre><code>A 1
  A 2
  B 1
  B 2
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>(A,(1,2))
  (B,(1,2))
  </code></pre>
  
  <p>I am able to do this with the following code:</p>
  
  <pre><code>data.groupByKey().mapValues(List(_))
  </code></pre>
  
  <p>The problem is that when I then try to do a Map operation like the following:</p>
  
  <pre><code>groupedData.map((k,v) =&gt; (k,v(0))) 
  </code></pre>
  
  <p>It tells me I have the wrong number of parameters.</p>
  
  <p>If I try:</p>
  
  <pre><code>groupedData.map(s =&gt; (s(0),s(1)))
  </code></pre>
  
  <p>It tells me that "(Any,List(Iterable(Any)) does not take parameters"</p>
  
  <p>No clue what I am doing wrong. Is my grouping wrong? What would be a better way to do this?</p>
  
  <p>Scala answers only please. Thanks!!</p>