The lazy val is declared as a member of the function, so each time the function is called there is a new lazy val being memoized.
Brian Maso On Tue, Apr 10, 2018 at 8:19 AM, <des.mag...@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. > -- Best regards, Brian Maso (949) 395-8551 Follow me: @bmaso br...@blumenfeld-maso.com -- 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.