Skip to content

Instantly share code, notes, and snippets.

@maizy
Created March 27, 2014 06:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maizy/9801350 to your computer and use it in GitHub Desktop.
Save maizy/9801350 to your computer and use it in GitHub Desktop.
var i = 7
def infStream(): Stream[Int] = i #:: infStream()
val stream = infStream()
println(stream.head)
// 7
println((stream take 3).toList)
// List(7, 7, 7)
i = 8
println((stream take 4).toList)
// List(7, 7, 7, 8)
i = 9
println((stream take 7).toList)
// List(7, 7, 7, 8, 9, 9, 9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment