Skip to content

Instantly share code, notes, and snippets.

@gclaramunt
Created December 13, 2010 13:34
Show Gist options
  • Save gclaramunt/738997 to your computer and use it in GitHub Desktop.
Save gclaramunt/738997 to your computer and use it in GitHub Desktop.
def ∑(r:Range)(f:Int =>Int)=r.reduceLeft(_+ f(_))
def ∏(r:Range)(f:Int =>Int)=r.reduceLeft(_* f(_))
// And now we can write:
val s= ∑(1 to 100)(x=>x^2)
val p= ∑(1 to 100 by 2)(x=>x^2)
val y= ∏(1 to 30 by 3)(_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment