Skip to content

Instantly share code, notes, and snippets.

@deeperunderstanding
Created December 22, 2019 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deeperunderstanding/3a3ee451a5ade3d790abca4ff649d3a4 to your computer and use it in GitHub Desktop.
Save deeperunderstanding/3a3ee451a5ade3d790abca4ff649d3a4 to your computer and use it in GitHub Desktop.
object WordCount extends MapReduce[String, String, Int, Int] {
override def mapper(line: String): Seq[KeyValue[String, Int]] =
"""[\w']+""".r.findAllIn(line).map { word => KeyValue(word, 1) }.toVector
override def reducer(key: String, values: Seq[Int]): KeyValue[String, Int] =
KeyValue(key, values.sum)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment