1

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?

Mingtao Zhang
  • 148
  • 10

1 Answers1

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