# Path: expremigen/patterns/pattern.py
# class Pattern(metaclass=abc.ABCMeta):
#     """
#     abstract base class for a Pattern
#     """
# 
#     def __str__(self):
#         return "{0}".format(self.__class__.__name__)
# 
#     def __repr__(self):
#         return self.__str__()
# 
# Path: expremigen/patterns/utils.py
# def take(n, iterable):
#     """Return first n items of the iterable as a list"""
#     return itertools.islice(iterable, n)
# 
# def geom(start=1, factor=2):
#     """
#     iterator to generate geometric series
#     :param start: start number
#     :param factor: constant factor to apply
#     :return: geometric series, e.g. geom(16, 0.5) -> 16 8 4 2 1 0.5 ...
#     """
#     # geom(1) --> 1 2 4 8 ...
#     # geom(16, 0.5) -> 16 8 4 2 1 0.5 ...
#     n = start
#     while True:
#         yield n
#         n *= factor


from expremigen.patterns.pattern import Pattern
from expremigen.patterns.utils import take, geom


class Pgeom(Pattern):
    """
    pattern that generates numbers in geometric series, e.g. Pgeom(1, 2, 5) -> 1, 2, 4, 8, 16
    """

    def __init__(self, frm=0, factor=1, length=5):
        """

        :param frm: starting number
        :param factor: factor by which to keep multiplying the starting number
        :param length: length of generated sequence
        """
        super().__init__()
        self.frm = frm
        self.factor = factor
        self.length = length

    def __iter__(self):

# Path: expremigen/patterns/pattern.py
# class Pattern(metaclass=abc.ABCMeta):
#     """
#     abstract base class for a Pattern
#     """
# 
#     def __str__(self):
#         return "{0}".format(self.__class__.__name__)
# 
#     def __repr__(self):
#         return self.__str__()
# 
# Path: expremigen/patterns/utils.py
# def take(n, iterable):
#     """Return first n items of the iterable as a list"""
#     return itertools.islice(iterable, n)
# 
# def geom(start=1, factor=2):
#     """
#     iterator to generate geometric series
#     :param start: start number
#     :param factor: constant factor to apply
#     :return: geometric series, e.g. geom(16, 0.5) -> 16 8 4 2 1 0.5 ...
#     """
#     # geom(1) --> 1 2 4 8 ...
#     # geom(16, 0.5) -> 16 8 4 2 1 0.5 ...
#     n = start
#     while True:
#         yield n
#         n *= factor


# Path: expremigen/patterns/pgeom.py
from expremigen.patterns.pattern import Pattern
from expremigen.patterns.utils import take, geom



class Pgeom(Pattern):
    """
    pattern that generates numbers in geometric series, e.g. Pgeom(1, 2, 5) -> 1, 2, 4, 8, 16
    """

    def __init__(self, frm=0, factor=1, length=5):
        """

        :param frm: starting number
        :param factor: factor by which to keep multiplying the starting number
        :param length: length of generated sequence
        """
        super().__init__()
        self.frm = frm
        self.factor = factor
        self.length = length

    def __iter__(self):

        return take(self.length, geom(self.frm, self.factor))