Skip to content

Instantly share code, notes, and snippets.

@Krasnyanskiy
Last active April 4, 2016 23:48
Show Gist options
  • Save Krasnyanskiy/bdf67fb45e9f76bad54621b5da2d812a to your computer and use it in GitHub Desktop.
Save Krasnyanskiy/bdf67fb45e9f76bad54621b5da2d812a to your computer and use it in GitHub Desktop.
-scala: foldr
val words = List("a", "b", "c", "d", "a", "c", "b", "a", "b", "d")
val res0 = words.map(w => (w, 1)).foldRight(("", 1)) {
case ((x1, y1), (x2, y2)) => (x1 + x2, y1 + y2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment