Skip to content

Instantly share code, notes, and snippets.

@tkaemming
Created March 6, 2015 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkaemming/3890749f6c3472b670e4 to your computer and use it in GitHub Desktop.
Save tkaemming/3890749f6c3472b670e4 to your computer and use it in GitHub Desktop.
import itertools
def pager(size):
for i in itertools.count():
if i % size == 0:
print 'fetching page:', i / size
yield i
def readahead(iterable, size=100):
actual, ahead = itertools.tee(iterable)
# advance the lookahead iterator
for _ in xrange(size):
next(ahead, None)
for item in actual:
yield item
next(ahead, None)
for item in itertools.islice(readahead(pager(50), 10), 250):
print item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment