<div dir="ltr">This same operator (except spelled as ??=) was up as a proposal and rejected in February. See <a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/7694">http://thread.gmane.org/gmane.comp.lang.swift.evolution/7694</a>.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 12, 2016 at 10:41 AM, Rod Brown 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’m tentatively supportive of this proposal. I definitely see the use case (assign only if not not nil). Interested to hear the opinions of others here :)<br>
<br>
-Rod<br>
<br>
<br>
> On 12 May 2016, at 11:59 PM, Jose Manuel Sánchez Peñarroja via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
> Sorry if this has already been discussed, if so I couldn’t find it.<br>
><br>
> I would like to propose to add to Swift an optional assignment operator ?=<br>
> I think this would nicely align with the other uses of ?, and avoid repetition in this case:<br>
><br>
> var value = 5<br>
><br>
> var possibleNewValue: Int? = nil<br>
><br>
> value = possibleNewValue ?? value<br>
><br>
> It would be used like this:<br>
><br>
> value ?= possibleNewValue<br>
><br>
> I’ve found quite a few cases in which this would be very useful to me. It is already possible to implement it, but having it defined in the standard library would define an standard, and prevent different semantics depending on who implements it.<br>
><br>
><br>
> infix operator ?= {<br>
> associativity right<br>
> precedence 90<br>
> assignment<br>
> }<br>
><br>
> func ?= <T>(inout lhs: T, rhs: T?) {<br>
> lhs = rhs ?? lhs<br>
> }<br>
><br>
><br>
> Regards,<br>
> José Manuel Sanchez<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>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Trent Nadeau</div>
</div>