Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit f0353bf

Browse files
authored
Merge pull request #440 from aogier/feature/deflating-iterator
slimming Result iterator
2 parents dd9adea + 4da2475 commit f0353bf

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/cloudant/result.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616
API module for interacting with result collections.
1717
"""
18+
from collections import deque
1819
from functools import partial
1920
from ._2to3 import STRTYPE
2021
from .error import ResultException
@@ -378,13 +379,13 @@ def _iterator(self, response):
378379
'''
379380

380381
while True:
381-
result = self._parse_data(response)
382+
result = deque(self._parse_data(response))
382383
del response
383384
if result:
384385
doc_count = len(result)
385386
last = result.pop()
386-
for row in result:
387-
yield row
387+
while result:
388+
yield result.popleft()
388389

389390
# We expect doc_count = self._page_size + 1 results, if
390391
# we have self._page_size or less it means we are on the

0 commit comments

Comments
 (0)