Created
March 12, 2017 01:34
-
-
Save ryandavidhartman/d6894ead55e0c956650ce69f2d8ae610 to your computer and use it in GitHub Desktop.
Basics Scala 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