Created
March 26, 2017 20:37
-
-
Save ryandavidhartman/64e146f282358a2a696796cef3376956 to your computer and use it in GitHub Desktop.
Classic Word count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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