Created
August 3, 2016 21:56
-
-
Save JoolsF/e7c9ab7c916a100adead85010f3c2adb to your computer and use it in GitHub Desktop.
Streams example - fibonacci and factorial
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
| lazy val fibs: Stream[BigInt] = | |
| BigInt(0) #:: | |
| BigInt(1) #:: | |
| fibs.zip(fibs.tail).map { n => n._1 + n._2 } | |
| lazy val N: Stream[BigInt] = BigInt(1) #:: N.map(_ + 1) | |
| lazy val fac: Stream[BigInt] = BigInt(1) #:: fac.zip(N).map(a => a._1 * a._2) | |
| fibs take 10 foreach println | |
| fac take 10 foreach println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment