Skip to content

Instantly share code, notes, and snippets.

@andrewharmellaw
Created May 21, 2013 19:23
Show Gist options
  • Save andrewharmellaw/5622470 to your computer and use it in GitHub Desktop.
Save andrewharmellaw/5622470 to your computer and use it in GitHub Desktop.
reduceLeft syntax
koan("Lists can be 'reduced' with a mathematical operation") {
val a = List(1, 3, 5, 7)
// note the two _s below indicate the first and second args respectively
a.reduceLeft(_ + _) should equal(16) // 1 + 3 + 5 + 7
a.reduceLeft(_ * _) should equal(105) // 1 * 3 * 5 * 7
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment