<div dir="ltr"><div dir="ltr">Maybe <a href="https://dlang.org/phobos/std_functional.html#memoize">https://dlang.org/phobos/std_functional.html#memoize</a> should helped you</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 29, 2019 at 4:15 PM Victor Porton via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I want to translate if possible the following from Python to D. <br>
Please help.<br>
<br>
---<br>
class cached_property(object):<br>
     """A version of @property which caches the value.  On access, <br>
it calls the<br>
     underlying function and sets the value in `__dict__` so <br>
future accesses<br>
     will not re-call the property.<br>
     """<br>
     def __init__(self, f):<br>
         self._fname = f.__name__<br>
         self._f = f<br>
<br>
     def __get__(self, obj, owner):<br>
         assert obj is not None, 'call {} on an <br>
instance'.format(self._fname)<br>
         ret = obj.__dict__[self._fname] = self._f(obj)<br>
         return ret<br>
---<br>
</blockquote></div>