FP in scala Chapter 5. How does the following work

Viewed 87

I see the following example on chapter 5 in FP in scala to drive home non-strictness

   val x = Cons(() => expensive(x), tl)
   val h1 = x.headOption
   val h2 = x.headOption

and I am trying to understand how

val x = Cons(() => expensive(x), tl) works? specifically the thunk () => expensive(x), given x itself is being defined?

0 Answers
Related