Skip to content

Instantly share code, notes, and snippets.

@ryandavidhartman
Created March 26, 2017 20:37
Show Gist options
  • Save ryandavidhartman/64e146f282358a2a696796cef3376956 to your computer and use it in GitHub Desktop.
Save ryandavidhartman/64e146f282358a2a696796cef3376956 to your computer and use it in GitHub Desktop.
Classic 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