renamed package to pypattyrn
This commit is contained in:
39
pypattyrn/behavioral/iterator.py
Normal file
39
pypattyrn/behavioral/iterator.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
|
||||
class Iterator(object):
|
||||
"""
|
||||
An Iterator class for the Iterator design pattern.
|
||||
|
||||
- External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Behavioral-Pattern-Usage}
|
||||
- External Iterator Pattern documentation: U{https://en.wikipedia.org/wiki/Iterator_pattern}
|
||||
"""
|
||||
def __init__(self, iterable):
|
||||
"""
|
||||
Initialize a new Iterator instance.
|
||||
|
||||
@param iterable: An Iterable object to iterate over.
|
||||
@type iterable: Iterable
|
||||
"""
|
||||
self.iterable = iterable
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
return self.iterable.__next__()
|
||||
|
||||
|
||||
class Iterable(object, metaclass=ABCMeta):
|
||||
"""
|
||||
An abstract class representing an Iterable object as part of the Iterator design pattern.
|
||||
|
||||
- External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Behavioral-Pattern-Usage}
|
||||
- External Iterator Pattern documentation: U{https://en.wikipedia.org/wiki/Iterator_pattern}
|
||||
"""
|
||||
@abstractmethod
|
||||
def __next__(self):
|
||||
"""
|
||||
All Iterable's must implement a __next__ method which eventually raises StopIteration.
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user