lazy variables

Paul Backus snarwin at gmail.com
Thu Oct 18 15:02:08 UTC 2018


On Thursday, 18 October 2018 at 14:08:11 UTC, aliak wrote:
> On Wednesday, 17 October 2018 at 23:34:55 UTC, Paul Backus 
> wrote:
>>
>> auto x = () {
>>     // do some heavy stuff
>> };
>>
>> if (condition) {
>>     func(x().y); // heavy stuff evaluated here
>> }
>
> That would do heavy stuff everytime i wanted to get y though 
> right?

Yes. If that's a problem, you could use `std.functional.memoize`, 
or Ali's solution.


More information about the Digitalmars-d-learn mailing list