Created
October 9, 2017 10:17
-
-
Save OOPMan/982fbaa39a16b93edc7f6046ca9be67d to your computer and use it in GitHub Desktop.
Class wrapping itertools.count to provide some additional functionality
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 | |
class Sequence(object): | |
""" | |
This class wraps itertools.count to provide additional bound means of | |
extracting data from the stream | |
""" | |
def __init__(self, start: int=0, step: int=1): | |
self._counter = itertools.count(start=start, step=step) | |
def just(self, n: int): | |
counter = 0 | |
while counter < n: | |
yield next(self._counter) | |
counter += 1 | |
@property | |
def just_one(self): | |
yield from self.just(1) | |
def __iter__(self): | |
return self._counter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment