Created
March 6, 2015 21:56
-
-
Save tkaemming/3890749f6c3472b670e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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