<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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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 </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=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></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. 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="">
> On Mar 23, 2016, at 2:32 AM, Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class="">
><br class="">
>> let john = {firstName="John"; lastName="Doe"}<br class="">
>> let alice = {john with FirstName="Alice"}<br class="">
>><br class="">
>> Current way to do this in Swift is:<br class="">
>><br class="">
>> let john = (firstName:"John", lastName:"Doe")<br class="">
>> var alice = john<br class="">
>> alice.firstName = "Alice"<br class="">
><br class="">
> I think this is better modeled in Swift as something like:<br class="">
><br class="">
> let john = (firstName:"John", lastName:"Doe")<br class="">
> let alice = with(john) {<br class="">
> $0.firstName = "Alice"<br class="">
> }<br class="">
><br class="">
> `with` would be something like:<br class="">
><br class="">
> func with<Value>(value: Value, function: Value throws -> Void) rethrows -> Value {<br class="">
> var mutableValue = value<br class="">
> return try function(&mutableValue)<br class="">
> }<br class="">
><br class="">
> This would serve many different purposes:<br class="">
><br class="">
> * If the value is a value type, allows you to return a modified copy<br class="">
> * Allows you to customize a value's properties immediately after initializing it, which many people have asked for<br class="">
> * Acts as a `tap` function when the block doesn't change the value (see <<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>>)<br class="">
><br class="">
> --<br class="">
> Brent Royal-Gordon<br class="">
> Architechies<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="">
<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>