Skip to content

Instantly share code, notes, and snippets.

@ryandavidhartman
Created March 12, 2017 01:34
Show Gist options
  • Save ryandavidhartman/d6894ead55e0c956650ce69f2d8ae610 to your computer and use it in GitHub Desktop.
Save ryandavidhartman/d6894ead55e0c956650ce69f2d8ae610 to your computer and use it in GitHub Desktop.
Basics Scala word count
def counter(file: String) = {
scala.io.Source.fromFile(file)
.getLines
.flatMap(_.split("\\W+"))
.foldLeft(Map.empty[String, Int]){
(count, word) => count + (word -> (count.getOrElse(word, 0) + 1))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment