Created
October 16, 2019 19:24
-
-
Save kleinron/d279e6661dbfd20f71e2f20c6452db3e 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
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