Last active
August 29, 2015 14:16
-
-
Save frgomes/5eb9005b07ec86417183 to your computer and use it in GitHub Desktop.
Scala - Sample usage of foldLeft
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
val init="aaa" | |
val s1 = List("b", "c", "d").foldLeft(init) { (acc, item) => acc + item } | |
println(s1) // prints: aaabcd | |
val s2 = ( "aaa" /: List("b", "c", "d")) { (acc, item) => acc + item } | |
println(s2) // prints: aaabcd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment