Skip to content

Instantly share code, notes, and snippets.

@natbusa
Last active August 29, 2015 13:57
Show Gist options
  • Save natbusa/9642233 to your computer and use it in GitHub Desktop.
Save natbusa/9642233 to your computer and use it in GitHub Desktop.
word count: scala
//read in
val text = scala.io.Source.fromFile("lorem.txt").mkString
val wc = text.
toLowerCase.
split("\\W+").
groupBy(identity).
mapValues( _.length )
//writeout
wc.foreach( kv => printf("%d %s\n", kv._2, kv._1 ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment