Skip to content

Instantly share code, notes, and snippets.

@andrewharmellaw
Created May 21, 2013 19:24
Show Gist options
  • Save andrewharmellaw/5622478 to your computer and use it in GitHub Desktop.
Save andrewharmellaw/5622478 to your computer and use it in GitHub Desktop.
FoldLeft syntax
koan("Foldleft is like reduce, but with an explicit starting value") {
val a = List(1, 3, 5, 7)
// NOTE: foldLeft uses a form called currying that we will explore later
a.foldLeft(0)(_ + _) should equal(16)
a.foldLeft(10)(_ + _) should equal(26)
a.foldLeft(1)(_ * _) should equal(105)
a.foldLeft(0)(_ * _) should equal(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment