When I debug, it shows "$Stream$Empty". But it didn't fall into .isEmpty case. I changed the pattern to "head #:: tail", it's working fine against some test cases. Could anyone explain what's happened behind the scenes?
Asked
Active
Viewed 453 times
1
-
7You need to show actual code. – ghik Nov 09 '13 at 20:31
-
2speculation: The stream is non empty in the sense that it has elements but non of these elements are realized yet. – Stefan Kunze Nov 09 '13 at 20:57
-
:( The codes are related to assignment from Functional Programming course in Coursera. – Mingtao Zhang Nov 10 '13 at 21:06
-
Possible duplicate of [Difference between Iterator and Stream in Scala?](http://stackoverflow.com/questions/1527962/difference-between-iterator-and-stream-in-scala) – Paul Sweatte Jun 17 '16 at 18:04
1 Answers
0
Is this helpful? isEmpty works great.
val strm = true #:: false #:: Stream[Boolean]()
def matchStream[T](stream:Stream[T]):List[String] = {
stream match {
case head #:: tail => head.toString :: matchStream(tail)
case stm if stm.isEmpty => List("end of stream")
}
}
matchStream(strm)
I ran this in a worksheet and got
res0: List[String] = List(true, false, end of stream)

Ion Freeman
- 512
- 4
- 19
-
This is a 3 year old question about debugger output, which your answer doesn't address. I doubt the OP (who hasn't visited SO in over a year) or anyone else is going to find this helpful. – jwvh Mar 21 '17 at 16:04