Created
March 16, 2015 22:57
-
-
Save muraiki/492539f842085f980349 to your computer and use it in GitHub Desktop.
groupBy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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