Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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