Skip to content

Instantly share code, notes, and snippets.

@klgraham
Created August 28, 2012 04:58
Show Gist options
  • Save klgraham/3495078 to your computer and use it in GitHub Desktop.
Save klgraham/3495078 to your computer and use it in GitHub Desktop.
Some *basic* functional scala
// 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