Skip to content

Instantly share code, notes, and snippets.

@JoolsF
Created August 3, 2016 21:56
Show Gist options
  • Select an option

  • Save JoolsF/e7c9ab7c916a100adead85010f3c2adb to your computer and use it in GitHub Desktop.

Select an option

Save JoolsF/e7c9ab7c916a100adead85010f3c2adb to your computer and use it in GitHub Desktop.
Streams example - fibonacci and factorial
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