Hello,
Please can some one explain why the following code blows the stack:
val fibs: Stream[BigInt] = BigInt(0) #:: BigInt(1) #:: fibs.zip(fibs.tail).map { n => n._1 + n._2 }.takeWhile(x => x < 4000000).filter(x => x % 2 == 0)
scala> fibs foreach println01
java.lang.StackOverflowError
If I take out the filter and apply it to the stream in another expression
as follows, it is fine:
scala> val fibs: Stream[BigInt] = BigInt(0) #:: BigInt(1) #:: fibs.zip(fibs.tail).map { n => n._1 + n._2 }.takeWhile(x => x < 4000000)
fibs: Stream[scala.math.BigInt] = Stream(0, ?)
scala> fibs filter ( x => x % 2 == 0)
res8: scala.collection.immutable.Stream[scala.math.BigInt] = Stream(0, ?)
scala> fibs filter ( x => x % 2 == 0) foreach println02834144610258410946463681964188320403524578
Why does it blow the stack with the first approach but not the second?
Thanks
Iftikhar
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.