[swift-evolution] [Pitch] Collection Type Element Property Observers
Joshua Alvarado
alvaradojoshua0 at gmail.com
Thu Mar 30 15:20:18 CDT 2017
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 <
swift-evolution at swift.org> 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
> allings at icloud.com
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
--
Joshua Alvarado
alvaradojoshua0 at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170330/34b9cc52/attachment.html>
More information about the swift-evolution
mailing list