Skip to content

Instantly share code, notes, and snippets.

@OOPMan
Created October 9, 2017 10:17
Show Gist options
  • Save OOPMan/982fbaa39a16b93edc7f6046ca9be67d to your computer and use it in GitHub Desktop.
Save OOPMan/982fbaa39a16b93edc7f6046ca9be67d to your computer and use it in GitHub Desktop.
Class wrapping itertools.count to provide some additional functionality
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