Last active
February 18, 2016 01:11
-
-
Save williamchan/34db8264bea7ae18f7f2 to your computer and use it in GitHub Desktop.
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
/** This is so slick. | |
* When working with Streams, use val instead of def so that memoization is enabled by default. | |
* | |
* Also see See http://derekwyatt.org/2011/07/29/understanding-scala-streams-through-fibonacci/ | |
*/ | |
import scala.math.BigInt | |
lazy val fibs: Stream[BigInt] = BigInt(0) #:: | |
BigInt(1) #:: | |
fibs.zip(fibs.tail).map { n => n._1 + n._2 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment