Skip to content

Instantly share code, notes, and snippets.

@j5ik2o
Forked from tyano/gist:1429205
Created December 4, 2011 04:50
Show Gist options
  • Save j5ik2o/1429210 to your computer and use it in GitHub Desktop.
Save j5ik2o/1429210 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