Helper to yield items from the parent iterator that match *value*. Items that don't match are stored in the local cache as they are encountered.
(self, value)
| 131 | return True |
| 132 | |
| 133 | def _get_values(self, value): |
| 134 | """ |
| 135 | Helper to yield items from the parent iterator that match *value*. |
| 136 | Items that don't match are stored in the local cache as they |
| 137 | are encountered. |
| 138 | """ |
| 139 | while True: |
| 140 | # If we've cached some items that match the target value, emit |
| 141 | # the first one and evict it from the cache. |
| 142 | if self._cache[value]: |
| 143 | yield self._cache[value].popleft() |
| 144 | # Otherwise we need to advance the parent iterator to search for |
| 145 | # a matching item, caching the rest. |
| 146 | else: |
| 147 | while True: |
| 148 | try: |
| 149 | item = next(self._it) |
| 150 | except StopIteration: |
| 151 | return |
| 152 | item_value = self._key(item) |
| 153 | if item_value == value: |
| 154 | yield item |
| 155 | break |
| 156 | elif self._validator(item_value): |
| 157 | self._cache[item_value].append(item) |
| 158 | |
| 159 | def __iter__(self): |
| 160 | for item in self._it: |
no test coverage detected