|
@@ -100,6 +100,7 @@ class Person:
|
|
|
class PersonCollection:
|
|
|
def __init__(self):
|
|
|
self._persons = {}
|
|
|
+ self.__it = None
|
|
|
|
|
|
def __getitem__(self, identifier: str) -> Person:
|
|
|
"""
|
|
@@ -132,3 +133,20 @@ class PersonCollection:
|
|
|
existing_person = self._persons[person.identifier]
|
|
|
existing_person.merge(person)
|
|
|
return existing_person
|
|
|
+
|
|
|
+ def __iter__(self) -> "PersonCollection":
|
|
|
+ """
|
|
|
+ >>> c = PersonCollection()
|
|
|
+ >>> for identifier in ['alice', 'bob', 'charlie']:
|
|
|
+ ... c.add_person(Person(identifier))
|
|
|
+ Person(alice)
|
|
|
+ Person(bob)
|
|
|
+ Person(charlie)
|
|
|
+ >>> list(c)
|
|
|
+ [Person(alice), Person(bob), Person(charlie)]
|
|
|
+ """
|
|
|
+ self.__it = iter(self._persons.values())
|
|
|
+ return self
|
|
|
+
|
|
|
+ def __next__(self) -> Person:
|
|
|
+ return next(self.__it)
|