I often come across a scenario where I have two collections of objects (either an array or the IteratorAggregate class), and I need to distinguish between the two lists.
Through diff, I mean:
- Detecting duplicate objects (duplicate detection logic will vary depending on the case)
- Add new objects
- Delete objects that are not in another list
Essentially, I'm looking for something like array_diffthat works with objects. So far, I have been repeating the same logic over and over for each type of collection. Obviously, since the conditions for repeating objects will differ from case to case, there is no particular solution. But is there a general outline or abstraction that people find an elegant way to handle this?
source
share