Skip to content

Instantly share code, notes, and snippets.

@sharathprabhal
Created November 13, 2013 21:48
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 sharathprabhal/7457037 to your computer and use it in GitHub Desktop.
Save sharathprabhal/7457037 to your computer and use it in GitHub Desktop.
def getCounts[T](list: Seq[T]): Map[T, Int] = list.foldLeft(Map.empty[T, Int]) { (m: Map[T, Int], x: T) => m + ((x, m.getOrElse(x, 0) + 1)) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment