Some interesting behavior with LazyList

Hello, i have some trouble.
Why it’s work without the function?

val lazyList: LazyList[Int] = 999 #::"").map(_.toInt).product)

And in function definition:

def digitalRoot(n: Int): Int = {
  val lazyList: LazyList[Int] = n #::"").foldLeft(0)(_ + _.toInt))

throw forward reference to value stream defined on line 2 extends over definition of value stream?

1 Like

Probably your first example was a class member. As a local, it must be a lazy val.

I think there was recent discussion whether to say this directly in the docs, or warn about it.

Thank you very much. I think it’s better to talk about it directly, because in docs specified val.

1 Like