guillermomuntaner / Burritos

A collection of Swift Property Wrappers (formerly "Property Delegates")
MIT License
1.33k stars 43 forks source link

AtomicWrite Collections #17

Closed fishcharlie closed 4 years ago

fishcharlie commented 4 years ago

First of all, amazing collection of Property Wrappers you have here!! Truly a great resource! So thank you!! 🎉

One thing I noticed, is the AtomicWrite property wrapper doesn't handle collections the best. I could be thinking about this wrong, but when accessing the underlying properties or functions, it doesn't do it in an Atomic way as far as I can tell. Since collections are just pointers to other items in memory, accessing those other items is not handled in an atomic way.

What are your thoughts on this? Do you think there is potential for maybe an extension on top of AtomicWrite that would help access the items in a collection in an Atomic way?

guillermomuntaner commented 4 years ago

Hi @fishcharlie.

The AtomicWrite wrapper has a mutate method that can be used for non trivial get/set logic, such as in the case you describe:

_collection.mutate {
    // Do something with your collection inside this block.
}

As those are intended to be general purpose utils, I don't see much point on making specific things for collections. I also don't have any good idea on how an API for this cool look like, but I am happy to get ideas. I you feel like trying, please give it a try and open a PR and we can discuss it there!

Regards.