Created
August 17, 2020 17:52
-
-
Save Sean-Bradley/2a04a0061ff84d553d01bfc0615ba419 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from abc import ABCMeta, abstractmethod | |
class IIterator(metaclass=ABCMeta): | |
@staticmethod | |
@abstractmethod | |
def has_next(): | |
"""Returns Boolean whether at end of collection or not""" | |
@staticmethod | |
@abstractmethod | |
def next(): | |
"""Return the object in collection""" | |
class Iterable(IIterator): | |
def __init__(self): | |
self.index = 0 | |
self.maximum = 7 | |
def next(self): | |
if self.index < self.maximum: | |
x = self.index | |
self.index += 1 | |
return x | |
else: | |
raise Exception("AtEndOfIteratorException", "At End of Iterator") | |
def has_next(self): | |
return self.index < self.maximum | |
ITERABLE = Iterable() | |
while ITERABLE.has_next(): | |
print(ITERABLE.next()) | |
# print(ITERABLE.next()) | |
# print(ITERABLE.next()) | |
# print(ITERABLE.next()) | |
# print(ITERABLE.next()) | |
# print(ITERABLE.next()) | |
# print(ITERABLE.next()) | |
# print(ITERABLE.next()) | |
# print(ITERABLE.next()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment