Skip to content

Instantly share code, notes, and snippets.

@dacr
Created March 28, 2013 21:20
Show Gist options
  • Save dacr/5266909 to your computer and use it in GitHub Desktop.
Save dacr/5266909 to your computer and use it in GitHub Desktop.
Append a stream A to a stream B doesn't imply evaluation of all items of the first Stream A.
#!/bin/sh
exec scala -deprecation -nocompdaemon "$0" "$@"
!#
def trace(x:Int) = {println(x); x}
val x=(1 to 5).toStream.map(trace _)
// 1 is printed
val y=(5 to 1 by -1).toStream.map(trace _)
// 5 is printed
val z=x++y
// nothing is printed
println("NOW let's materialize the stream")
z.toList
// 2 3 4 5 4 3 2 1 is printed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment