Skip to content

Instantly share code, notes, and snippets.

@tyano
Created December 4, 2011 04:48
Show Gist options
  • Save tyano/1429205 to your computer and use it in GitHub Desktop.
Save tyano/1429205 to your computer and use it in GitHub Desktop.
List(1, 2, 3, 1) を Map(1 -> 2, 2 -> 1, 3 -> 1)
List(1,2,3,1).zip(List(1,1,1,1)).foldLeft(Map[Int,Int]()) { (x, y) => x.get(y._1) match { case Some(v) => x + Pair(y._1, (v + y._2)) case None => x + y }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment