I believe this will this impact performance on collections if you have to
do a computation on every item.

Also what about appending another collection to an existing collection?
Will there be a willAdd(newValue: Collection)?
Or will the willAdd(element: Element) be called multiple times?

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.

On Thu, Mar 30, 2017 at 12:37 PM, Sean Alling via swift-evolution <
[email protected]> wrote:

> *PROPOSAL:*
>
> I propose the addition of the following new property observers applicable
> to all Collection types (Dictionary, Set, and Array):
>
> – *willAdd(newValue) { … }*
> – *didAdd(newValue) { … }*
>
> – *willRemove(oldValue) { … }*
> – *didRemove(oldValue) { … }*
>
> where, `newValue` and `oldValue` are *immutable*.
>
> 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.
>
> 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.
>
>
> *EXAMPLE USAGE:*
>
> var list = [objects]() {
> willAdd(newValue) {
> …
> }
> didAdd(newValue) {
> …
> }
> }
>
> var list = [key : object]() {
> willRemove(oldValue) {
> …
> }
> didRemove(oldValue) {
> …
> }
> }
>
>
> -----
> Sean Alling
> [email protected]
>
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>


-- 
Joshua Alvarado
[email protected]
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to