<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I would very much like a standardized way of doing this. I am currently writing a game implementation in a functional style and the syntax for updating fields in pretty clunky. I’d like to avoid having to explicitly use var’s at all to accomplish it.<div class=""><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 23, 2016, at 7:29 AM, James Campbell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Yeah a way to have a function that mutates a struct return a new copy with that mutation would be awesome ! Rather than mutating in place.</div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><p class=""><b class=""><font color="#cc0000" class="">___________________________________</font></b></p><p class=""><b class="">James⎥Head Of CEO</b></p><p class=""><b class=""><font color="#cc0000" class=""><a href="mailto:james@supmenow.com" target="_blank" class="">james@supmenow.com</a>⎥<a href="http://supmenow.com/" target="_blank" class="">supmenow.com</a></font></b></p><p class=""><b class=""><font size="2" class="">Sup</font></b></p><p class=""><b class=""><font size="2" class="">Runway East
</font></b></p><p class=""><b class=""><font size="2" class="">10 Finsbury Square</font></b></p><p class=""><b class=""><font size="2" class="">London</font></b></p><p class=""><b class=""><font size="2" class="">
EC2A 1AF&nbsp;</font></b></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<br class=""><div class="gmail_quote">On Wed, Mar 23, 2016 at 2:28 PM, William Dillon via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I like this.&nbsp; I’m always annoyed when I need var just because I can’t get all my initialization done with let.<br class="">
<br class="">
- Will<br class="">
<div class="HOEnZb"><div class="h5"><br class="">
&gt; On Mar 23, 2016, at 2:32 AM, Brent Royal-Gordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">
&gt;<br class="">
&gt;&gt; let john = {firstName="John"; lastName="Doe"}<br class="">
&gt;&gt; let alice = {john with FirstName="Alice"}<br class="">
&gt;&gt;<br class="">
&gt;&gt;&nbsp; Current way to do this in Swift is:<br class="">
&gt;&gt;<br class="">
&gt;&gt; let john = (firstName:"John", lastName:"Doe")<br class="">
&gt;&gt; var alice = john<br class="">
&gt;&gt; alice.firstName = "Alice"<br class="">
&gt;<br class="">
&gt; I think this is better modeled in Swift as something like:<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;let john = (firstName:"John", lastName:"Doe")<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;let alice = with(john) {<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$0.firstName = "Alice"<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;}<br class="">
&gt;<br class="">
&gt; `with` would be something like:<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;func with&lt;Value&gt;(value: Value, function: Value throws -&gt; Void) rethrows -&gt; Value {<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var mutableValue = value<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return try function(&amp;mutableValue)<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp;}<br class="">
&gt;<br class="">
&gt; This would serve many different purposes:<br class="">
&gt;<br class="">
&gt; * If the value is a value type, allows you to return a modified copy<br class="">
&gt; * Allows you to customize a value's properties immediately after initializing it, which many people have asked for<br class="">
&gt; * Acts as a `tap` function when the block doesn't change the value (see &lt;<a href="http://ruby-doc.org/core-2.3.0/Object.html#method-i-tap" rel="noreferrer" target="_blank" class="">http://ruby-doc.org/core-2.3.0/Object.html#method-i-tap</a>&gt;)<br class="">
&gt;<br class="">
&gt; --<br class="">
&gt; Brent Royal-Gordon<br class="">
&gt; Architechies<br class="">
&gt;<br class="">
&gt; _______________________________________________<br class="">
&gt; swift-evolution mailing list<br class="">
&gt; <a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</div></div></blockquote></div><br class=""></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>