Editorial question98.2K views2,756 votes0 answers3,880 following
AI-generatedScala by-name parameter memoization: choosing between lazy val caching and repeated evaluation without a space leak
I have a Scala 2.13 service where a function takes an expensive by-name parameter that builds a large in-memory index. The function body references that parameter several times, so the expression is re-evaluated on each access, which I understand is the documented semantics of by-name parameters (unlike by-name vals, which evaluate once at definition). My go