<div dir="ltr">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"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">
<p><b><font color="#cc0000">___________________________________</font></b></p><p><b>James⎥Head Of CEO</b></p><p><b><font color="#cc0000"><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a>⎥<a href="http://supmenow.com" target="_blank">supmenow.com</a></font></b></p><p><b><font size="2">Sup</font></b></p><p><b><font size="2">Runway East
</font></b></p><p><b><font size="2">10 Finsbury Square</font></b></p><p><b><font size="2">London</font></b></p><p><b><font size="2">
EC2A 1AF </font></b></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Wed, Mar 23, 2016 at 2:28 PM, William Dillon via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><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>
<br>
- Will<br>
<div class="HOEnZb"><div class="h5"><br>
> On Mar 23, 2016, at 2:32 AM, Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
>> let john = {firstName="John"; lastName="Doe"}<br>
>> let alice = {john with FirstName="Alice"}<br>
>><br>
>> Current way to do this in Swift is:<br>
>><br>
>> let john = (firstName:"John", lastName:"Doe")<br>
>> var alice = john<br>
>> alice.firstName = "Alice"<br>
><br>
> I think this is better modeled in Swift as something like:<br>
><br>
> let john = (firstName:"John", lastName:"Doe")<br>
> let alice = with(john) {<br>
> $0.firstName = "Alice"<br>
> }<br>
><br>
> `with` would be something like:<br>
><br>
> func with<Value>(value: Value, function: Value throws -> Void) rethrows -> Value {<br>
> var mutableValue = value<br>
> return try function(&mutableValue)<br>
> }<br>
><br>
> This would serve many different purposes:<br>
><br>
> * If the value is a value type, allows you to return a modified copy<br>
> * Allows you to customize a value's properties immediately after initializing it, which many people have asked for<br>
> * 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">http://ruby-doc.org/core-2.3.0/Object.html#method-i-tap</a>>)<br>
><br>
> --<br>
> Brent Royal-Gordon<br>
> Architechies<br>
><br>
> _______________________________________________<br>
> swift-evolution mailing list<br>
> <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div>