<reponame>eugene-eeo/prudent
from itertools import chain
from collections import deque


class Stream(object):
    """
    This datastructure forms the core of other lazy
    data structures. You are recommended to subclass
    this class when making something new, e.g. a
    lazily loaded set.
    """

    def __init__(self, iterable=()):
        self.queue = deque()
        self.extend(iterable)

    def __add__(self, other):
        return self.__class__(chain(self, other))

    def __iter__(self):
        while self.queue:
            for datum in self.queue[0]:
                yield datum
            self.queue.popleft()

    def extend(self, it):
        """
        Extends the current stream in-place.
        """
        self.queue.append(iter(it))

from itertools import chain
from collections import deque


class Stream(object):
    """
    This datastructure forms the core of other lazy
    data structures. You are recommended to subclass
    this class when making something new, e.g. a
    lazily loaded set.
    """

    def __init__(self, iterable=()):
        self.queue = deque()
        self.extend(iterable)

    def __add__(self, other):
        return self.__class__(chain(self, other))

    def __iter__(self):
        while self.queue:
            for datum in self.queue[0]:
                yield datum
            self.queue.popleft()

    def extend(self, it):
        """
        Extends the current stream in-place.
        """
        self.queue.append(iter(it))
This datastructure forms the core of other lazy     data structures. You are recommended to subclass     this class when making something new, e.g. a     lazily loaded set. Extends the current stream in-place.