Last active
August 29, 2015 14:17
-
-
Save klaeufer/867abb57dddc1b247b52 to your computer and use it in GitHub Desktop.
Scala Iterator loop idiom (stateless): repeatedly apply an endofunction until a condition is met
This file contains 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
scala> def f(i: Int) = i * i | |
f: (i: Int)Int | |
scala> Iterator.iterate(2)(f) | |
res11: Iterator[Int] = non-empty iterator | |
scala> res11 takeWhile { _ < 10 } foreach { println } | |
2 | |
4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment