<div dir="ltr">Hi, quick question here:<div><br></div><div>I have a class with a property that needs to be really *really* lazy. So lazy, in fact, that when you assign to that property, the class actually stores a closure of what you assigned, which is only evaluated if and when you actually attempt to read the property.</div><div><br></div><div>Simplified:</div><div><br></div><div><font face="monospace, monospace">class Foo {</font></div><div><font face="monospace, monospace">  private var valueSource: () -&gt; Bar</font></div><div><font face="monospace, monospace">  private var valueCache: Bar?</font></div><div><font face="monospace, monospace">  </font></div><div><font face="monospace, monospace">  init(_ v: @escaping @autoclosure () -&gt; Bar) {</font></div><div><font face="monospace, monospace">    valueSource = v</font></div><div><font face="monospace, monospace">  }</font></div><div><font face="monospace, monospace">  </font></div><div><font face="monospace, monospace">  var value: Bar {<br></font></div><div><font face="monospace, monospace">    get {</font></div><div><div><span style="font-family:monospace,monospace">      if let v = valueCache { return v }</span><font face="monospace, monospace"><br class="gmail-Apple-interchange-newline"></font></div><div><span style="font-family:monospace,monospace">      let w = valueSource()</span><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace">      valueCache = w</span><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace">      return w</span></div></div><div><span style="font-family:monospace,monospace">    }</span><br></div><div><font face="monospace, monospace">    </font><span style="font-family:monospace,monospace">set {</span></div><div><font face="monospace, monospace">      /* ??? */</font></div><div><font face="monospace, monospace">    }</font></div><div><font face="monospace, monospace">  }</font></div><div><font face="monospace, monospace">  </font></div><div><font face="monospace, monospace">  // I want this function&#39;s logic to go in the setter above</font></div><div><font face="monospace, monospace">  func setValue(_ v: @escaping @autoclosure () -&gt; Bar) {</font></div><div><font face="monospace, monospace">    valueSource = v</font></div><div><font face="monospace, monospace">    valueCache = nil</font></div><div><font face="monospace, monospace">  }</font></div><div><font face="monospace, monospace">}</font></div><div><br></div><div>The goal is to be able to write things like “someFoo.value = bar1 / bar2” (or even more complex expressions) and not evaluate them until/unless the result is actually needed.</div><div><br></div><div>Currently I am using “someFoo.setValue( bar1 / bar2 )”, which is not nearly as ergonomic as the assignment syntax. So, is there a way to make this work?</div><div><br></div><div>Nevin</div></div>