Skip to content

Instantly share code, notes, and snippets.

@williamchan
Last active February 18, 2016 01:11
Show Gist options
  • Save williamchan/34db8264bea7ae18f7f2 to your computer and use it in GitHub Desktop.
Save williamchan/34db8264bea7ae18f7f2 to your computer and use it in GitHub Desktop.
/** 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