Created
May 21, 2013 19:24
-
-
Save andrewharmellaw/5622478 to your computer and use it in GitHub Desktop.
FoldLeft syntax
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
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