title: Simplest way to count words in a file
body: <p>I'm trying to code in the simplest way a program to count word occurrences in file in Scala Language. So far I have these piece of code:</p>
  
  <pre><code>import scala.io.Codec.string2codec
  import scala.io.Source
  import scala.reflect.io.File
  
  object WordCounter {
      val SrcDestination: String = ".." + File.separator + "file.txt"
      val Word = "\\b([A-Za-z\\-])+\\b".r
  
      def main(args: Array[String]): Unit = {
  
          val counter = Source.fromFile(SrcDestination)("UTF-8")
                  .getLines
                  .map(l =&gt; Word.findAllIn(l.toLowerCase()).toSeq)
                  .toStream
                  .groupBy(identity)
                  .mapValues(_.length)
  
          println(counter)
      }
  }
  </code></pre>
  
  <p>Don't bother of regexp expression. I would like to know how to extract single words from
  sequence retrieved in this line:</p>
  
  <pre><code>map(l =&gt; Word.findAllIn(l.toLowerCase()).toSeq)
  </code></pre>
  
  <p>in order to get each word occurency counted. Currently I'm getting map with counted words sequences.</p>