Created
November 6, 2013 14:18
-
-
Save hanbzu/7336741 to your computer and use it in GitHub Desktop.
Scala: Stream concatenation. Thanks to Pavel Lepin.
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
val a = Stream(1) | |
//a: scala.collection.immutable.Stream[Int] = Stream(1, ?) | |
def b: Stream[Int] = Stream(b.head) | |
//b: Stream[Int] | |
a #::: b | |
//res0: scala.collection.immutable.Stream[Int] = Stream(1, ?) | |
a append b | |
//res1: scala.collection.immutable.Stream[Int] = Stream(1, ?) | |
a ++ b | |
//java.lang.StackOverflowError | |
// at scala.package$.Stream(package.scala:74) | |
// at .b(<console>:7) | |
// (etc.) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this has nothing to do with concatenation. Just doing
b.take(2)
results in aStackOverFlowError
. It's a recursive method without a base case so no surprise there.