Ah OK. So I am guessing I misunderstood section 5.2.1. The "cons" function 
is only ever called once in this scenario?

On Tuesday, 10 April 2018 17:19:24 UTC+2, des.m...@gmail.com wrote:
>
> Hi
>
> Based on my understanding of the explanation of lazy val memoization in 
> section 5.2.1, I would have thought that if I define the following function:
>
>     def func(i: => Int): Unit = {
>         lazy val cached = {
>             println("Calculating")
>             i * i
>         }
>         cached
>     }
>
> And then made the following calls:
>
> func(3)
> func(3)
>
> that my lazy evaluation should only happen once? - as the function is 
> getting called with the same parameter the second time. But this is not the 
> case when I test. Could someone explain what I am missing here?
>
> Thanks
> Des
>

-- 
You received this message because you are subscribed to the Google Groups 
"scala-functional" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to scala-functional+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to