Skip to content

Instantly share code, notes, and snippets.

@muraiki
Created March 16, 2015 22:57
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 muraiki/492539f842085f980349 to your computer and use it in GitHub Desktop.
Save muraiki/492539f842085f980349 to your computer and use it in GitHub Desktop.
groupBy
def groupBy[A](xs: List[A]): Map[A, Int] =
xs.foldLeft(Map[A, Int]()) { (m: Map[A, Int], x: A) => m + (x -> (m.get(x).getOrElse(0) + 1)) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment