Skip to content

Instantly share code, notes, and snippets.

@sharathprabhal
Last active December 25, 2015 00:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sharathprabhal/6890475 to your computer and use it in GitHub Desktop.
val s = Seq("apple", "oranges", "apple", "banana", "apple", "oranges", "oranges")
s.foldLeft(Map.empty[String, Int]) { (m, x) => m + ((x, m.getOrElse(x, 0) + 1)) }
// output: scala.collection.immutable.Map[String,Int] = Map(apple -> 3, oranges -> 3, banana -> 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment