<div dir="ltr">I believe this will this impact performance on collections if you have to do a computation on every item. <div><br></div><div>Also what about appending another collection to an existing collection? </div><div>Will there be a willAdd(newValue: Collection)? </div><div>Or will the willAdd(element: Element) be called multiple times? <div><br><div>I think think the gain of functionality isn't there for the addition of this functionality to be added. There are other ways to implement what you are desiring to do without adding it to Swift language.<br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 30, 2017 at 12:37 PM, Sean Alling 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"><div style="word-wrap:break-word"><div style="margin:0px;line-height:normal"><span style="text-decoration:underline;font-kerning:none"><b>PROPOSAL:</b></span></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">I propose the addition of the following new property observers applicable to all Collection types (Dictionary, Set, and Array):</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">– <b>willAdd(newValue) { … }</b></span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">– <b>didAdd(newValue) { … }</b></span></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">– <b>willRemove(oldValue) { … }</b></span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">– <b>didRemove(oldValue) { … }</b></span></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">where, `</span><span style="text-decoration:underline;font-kerning:none">newValue</span><span style="font-kerning:none">` and `</span><span style="text-decoration:underline;font-kerning:none">oldValue</span><span style="font-kerning:none">` are <b>immutable</b>.</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">This would allow one to perform additional work or observer logic to values added and removed from collections. This model is consistent with Swift syntax and may perhaps minimize the use of NSNotifications in some situations.</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">Currently, in order to perform this functionality some filtering and comparison logic would have to be performed from within a `willSet { … }` and `didSet { …}` call. This change would not only ease that burden but promote a more visible and explicit expression that can further improve readability and traceability of functionality.</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal"><span style="text-decoration:underline;font-kerning:none"><b>EXAMPLE USAGE:</b></span></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">var list = [objects]() {</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">        </span>willAdd(newValue) {</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">                </span>… </span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">        </span>}</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">        </span>didAdd(newValue) {</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">                </span>…</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">        </span>}</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">}</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">var list = [key : object]() {</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">        </span>willRemove(oldValue) {</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">                </span>…</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">        </span>}</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">        </span>didRemove(oldValue) {</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">                </span>…</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none"><span class="m_4151872266957475023Apple-tab-span" style="white-space:pre-wrap">        </span>}</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">}</span></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal;min-height:14px"><span style="font-kerning:none"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">-----</span></div><div style="margin:0px;line-height:normal"><span style="font-kerning:none">Sean Alling</span></div><div style="margin:0px;line-height:normal;color:rgb(0,105,217)"><span style="text-decoration:underline;font-kerning:none"><a href="mailto:allings@icloud.com" target="_blank">allings@icloud.com</a></span></div></div><br>______________________________<wbr>_________________<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/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Joshua Alvarado<div><a href="mailto:alvaradojoshua0@gmail.com" target="_blank">alvaradojoshua0@gmail.com</a></div></div>
</div>