Commits

Lynn Rees committed 61aad51

- better repr
- exhaust call method

Comments (0)

Files changed (5)

 except ImportError:
     from distutils.core import setup
 
-install_requires = ['stuf>=0.8.9']
+install_requires = ['stuf>=0.8.11']
 
 setup(
     name='twoq',
-    version='0.4.6',
+    version='0.4.7',
     description='iterator chaining, underscored by a two-headed queue',
     long_description=open(os.path.join(os.getcwd(), 'README.rst'), 'r').read(),
     author='L. C. Rees',
 
 __all__ = ('twoq', 'manq', 'autoq', 'port')
 
-__version__ = (0, 4, 6)
+__version__ = (0, 4, 7)

twoq/active/mixins.py

 
 from twoq.mixins.queuing import ThingsMixin, ResultMixin
 
+
 __all__ = ('AutoQMixin', 'ManQMixin', 'AutoResultMixin', 'ManResultMixin')
 
 
         # utility things
         self._util = deque_()
 
+    def __repr__(self):
+        getr_, list_ = self._getr, self._list
+        return (
+            '<{}.{}([IN: {}({}) => WORK: {}({}) => UTIL: {}({}) => '
+            'OUT: {}: ({})]) at {}'
+        ).format(
+            self.__module__,
+            self._clsname(self),
+            self._INQ,
+            list_(getr_(self._INQ)),
+            self._WORKQ,
+            list_(getr_(self._WORKQ)),
+            self._UTILQ,
+            list_(getr_(self._UTILQ)),
+            self._OUTQ,
+            list_(getr_(self._OUTQ)),
+            id(self),
+        )
+
     ###########################################################################
     ## thing length ###########################################################
     ###########################################################################

twoq/lazy/mixins.py

 
 from twoq.mixins.queuing import ResultMixin, ThingsMixin
 
+
 __all__ = ('AutoQMixin', 'ManQMixin', 'AutoResultMixin', 'ManResultMixin')
 
 
         # utility things
         self._util = iter_([])
 
+    def __repr__(self):
+        getr_, setr_, list_ = self._getr, self._setr, self._list
+        in1, in2 = self._split(getr_(self._INQ))
+        setr_(self._INQ, in1)
+        out1, out2 = self._split(getr_(self._OUTQ))
+        setr_(self._OUTQ, out1)
+        work1, work2 = self._split(getr_(self._WORKQ))
+        setr_(self._WORKQ, work1)
+        util1, util2 = self._split(getr_(self._UTILQ))
+        setr_(self._UTILQ, util1)
+        return (
+            '<{}.{}([IN: {}({}) => WORK: {}({}) => UTIL: {}({}) => '
+            'OUT: {}: ({})]) at {}>'
+        ).format(
+            self.__module__,
+            self._clsname(self),
+            self._INQ,
+            list_(in2),
+            self._WORKQ,
+            list_(work2),
+            self._UTILQ,
+            list_(util2),
+            self._OUTQ,
+            list_(out2),
+            id(self),
+        )
+
     ###########################################################################
     ## length #################################################################
     ###########################################################################

twoq/mixins/queuing.py

 from operator import methodcaller
 from contextlib import contextmanager
 
-from stuf.utils import lazy
+from stuf.six import u
+from stuf.utils import lazy, clsname
 
 from twoq import support
 
     ## optimize lookups #######################################################
     ###########################################################################
 
+    _clsname = lazier(clsname)
     _deek = lazier(deque)
     _filterfalse = lazier(support.filterfalse)
     _ichain = lazier(itertools.chain.from_iterable)
     _split = lazier(itertools.tee)
     _starmap = lazier(itertools.starmap)
     _sum = lazier(sum)
+    _u = lazier(u)
 
     @lazy
     def _getr(self):
         @param filter: a filter to apply to mapping (default: `None`)
         @param exception: exception sentinel (default: `StopIteration`)
         '''
-        next_, starmap_, items_ = cls._next, cls._starmap, cls._items
-        subiter = cls._ifilter(filter, items_(map)) if filter else items_(map)
+        next_, items_ = cls._next, cls._items
+        iterable = cls._starmap(
+            call, cls._ifilter(filter, items_(map)) if filter else items_(map),
+        )
         try:
             while 1:
-                next_(starmap_(call, subiter))
+                next_(iterable)
+        except exception:
+            pass
+
+    @classmethod
+    def exhaustcall(cls, call, iterable, exception=StopIteration):
+        '''
+        call function on an iterator until it's exhausted
+
+        @param call: call that does the exhausting
+        @param iterable: iterable to exhaust
+        @param exception: exception marking end of iteration
+        '''
+        next_ = cls._next
+        iterable = cls._imap(call, iterable)
+        try:
+            while True:
+                next_(iterable)
         except exception:
             pass