Created
August 28, 2012 04:58
-
-
Save klgraham/3495078 to your computer and use it in GitHub Desktop.
Some *basic* functional scala
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
// x = Range(1, ..., 10) | |
val x = 1 to 10 | |
x.sum | |
// two ways to fold left | |
x.foldLeft(0)(_ + _) | |
(0 /: x)(_ + _) | |
// two ways to fold right | |
x.foldRight(0)(_ + _) | |
(x :\ 0)(_ + _) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment