title: Reduce a List of tuples in Spark
body: <p>I have a List of tuples : <code>val re = List((2,3), (3,5), (2,4))</code>   </p>
  
  <p>I'm attempting to reduce this List so that each second parameter of the tuple is summed.</p>
  
  <p>So <code>List((2,3), (3,5), (2,4))</code></p>
  
  <p>becomes</p>
  
  <pre><code>List((2,7) , (3,5))
  </code></pre>
  
  <p>I've been researching the Scala Spark examples : <a href="https://spark.apache.org/examples.html" rel="nofollow">https://spark.apache.org/examples.html</a> such as word count : </p>
  
  <pre><code>val counts = file.flatMap(line =&gt; line.split(" "))
                   .map(word =&gt; (word, 1))
                   .reduceByKey(_ + _)
  </code></pre>
  
  <p>But when I try something similar on my collection I receive error : </p>
  
  <pre><code>scala&gt; re.reduceByKey(_ + _)
  &lt;console&gt;:13: error: value reduceByKey is not a member of List[(Int, Int)]
                re.reduceByKey(_ + _)
                   ^
  </code></pre>
  
  <p>How can I use reduce function on a List of tuples ?</p>