Created
June 4, 2011 04:02
-
-
Save tafsiri/1007562 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 words = List("this", "is", "a", "list", "of", "strings") | |
| //foldLeft function (curried) | |
| var size = words.foldLeft(0)((sum, word) => sum + 1) | |
| var charCount = words.foldLeft(0)((sum, word) => sum + word.length()) | |
| println(size) | |
| println(charCount) | |
| //foldleft operator | |
| //I definitely prefer the curried function form, why do we need curly braces around this code | |
| //block? Other function take code blocks without curly braces. Tate text doesn't explain | |
| //what these variations arise from, which irks me somewhat. | |
| charCount = (0 /: words) {(sum, word) => sum + word.length()} | |
| println(charCount) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment