title: Scala - reduce function
body: <p>How to use reduce function in Scala? Is there a built in function like that?
  I have implemented a program to find word count in scala.</p>
  
  <pre><code>object count {
      def main(args: Array[String]) {
          val fruits = List("apple", "apple", "orange", "apple", "mango", "orange")
          val word = fruits.flatMap(_.split("\n"))
          val Map = word.map(word =&gt; (word,1)).groupBy(_._1)
          val reduce = Map.map(word =&gt; (word._1,word._2.foldLeft(0)((sum,c) =&gt; sum+ c._2)))
          println(reduce)     }} 
  </code></pre>
  
  <p>How to replace foldleft with reduce function?</p>