Skip to content

Instantly share code, notes, and snippets.

@hanbzu
Created November 6, 2013 14:18
Show Gist options
  • Save hanbzu/7336741 to your computer and use it in GitHub Desktop.
Save hanbzu/7336741 to your computer and use it in GitHub Desktop.
Scala: Stream concatenation. Thanks to Pavel Lepin.
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.)
@poohsen
Copy link

poohsen commented Nov 15, 2022

this has nothing to do with concatenation. Just doing b.take(2) results in a StackOverFlowError. It's a recursive method without a base case so no surprise there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment