Created
March 17, 2013 09:39
-
-
Save dacr/5180825 to your computer and use it in GitHub Desktop.
list, view and stream - An example to understand the differences
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
#!/bin/sh | |
exec scala -deprecation -nocompdaemon "$0" "$@" | |
!# | |
val l=List(0, 1, 2) | |
var x=1 | |
val m1=l.map(_ +x) // c1 | |
val v1=l.view.map(_+x) // c2 | |
val s1=l.toStream.map(_+x) // c3 | |
x=2 | |
println("--------- x=2 ---------") | |
println("the list :"+m1) // List(1, 2, 3) c4 | |
println("from view :"+v1.toList) // List(2, 3, 4) c5 | |
println("from stream :"+s1.toList) // List(1, 3, 4) c6 | |
println("--------- x=3 ---------") | |
x=3 | |
println("the list :"+m1) // List(1, 2, 3) c7 | |
println("from view :"+v1.toList) // List(3, 4, 5) c8 | |
println("from stream :"+s1.toList) // List(1, 3, 4) c9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment