Skip to content

Instantly share code, notes, and snippets.

@kleinron
Created October 16, 2019 19:24
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 kleinron/d279e6661dbfd20f71e2f20c6452db3e to your computer and use it in GitHub Desktop.
Save kleinron/d279e6661dbfd20f71e2f20c6452db3e to your computer and use it in GitHub Desktop.
class hn_wrapper(object):
def __init__(self, it):
self.it = iter(it)
self._hasnext = None
def __iter__(self): return self
def next(self):
if self._hasnext:
result = self._thenext
else:
result = next(self.it)
self._hasnext = None
return result
def hasnext(self):
if self._hasnext is None:
try: self._thenext = next(self.it)
except StopIteration: self._hasnext = False
else: self._hasnext = True
return self._hasnext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment