Commits

Lynn Rees committed 697b145

- test

Comments (0)

Files changed (10)

 
 setup(
     name='twoq',
-    version='0.4.11',
+    version='0.4.12',
     description='iterator chaining, underscored by a two-headed queue',
     long_description=open(join(getcwd(), 'README.rst'), 'r').read(),
     keywords='queue generator utility iterator functional programming',
 
 __all__ = ('twoq', 'manq', 'autoq', 'port')
 
-__version__ = (0, 4, 11)
+__version__ = (0, 4, 12)

twoq/filtering.py

 
     '''collecting mixin'''
 
-    @staticmethod
-    def _members(iterable):
-        '''
-        collect members of things
-
-        @param thing: an iterable
-        '''
-        getattr_, AttributeError_ = getattr, AttributeError
-        for key in dir(iterable):
-            try:
-                thing = getattr_(iterable, key)
-            except AttributeError_:
-                pass
-            else:
-                yield key, thing
-
     @classmethod
-    def _walk(cls, truth, subcall, transform, iterable):
+    def _extract(cls, truth, subcall, transform, iterable):
         '''
         collect members of things
 
         @param truth: second "Truth" filter
         @param iterable: an iterable
         '''
-        getattr_, AttributeError_, walk_ = getattr, AttributeError, cls._walk
-        for key in cls._ifilter(truth, dir(iterable)):
-            try:
-                thing = getattr_(iterable, key)
-            except AttributeError_:
-                pass
-            else:
-                if subcall(thing):
-                    yield key, transform(
-                        walk_(truth, subcall, transform, thing)
-                    )
+        def members(
+            f, s, t, i, d_=dir, w_=cls._extract, g=getattr, e=AttributeError,
+        ): #@IgnorePep8
+            for k in d_(i):
+                try:
+                    v = g(i, k)
+                except e:
+                    pass
                 else:
-                    yield key, thing
+                    if s(v):
+                        yield k, t(w_(f, s, t, v))
+                    else:
+                        yield k, v
+        for member in cls._ifilter(
+            truth, members(truth, subcall, transform, iterable),
+        ):
+            yield member
 
     @classmethod
     def _mfilter(cls, call, iterable):
         @param call: "Truth" filter
         @param iterable: an iterable
         '''
-        for i in cls._ifilter(call, cls._members(iterable)):
+        def members(iterable):
+            getattr_, AttributeError_ = getattr, AttributeError
+            for key in dir(iterable):
+                try:
+                    thing = getattr_(iterable, key)
+                except AttributeError_:
+                    pass
+                else:
+                    yield key, thing
+        for i in cls._ifilter(call, members(iterable)):
             yield i
 
     @staticmethod
 
     def deepmembers(self):
         '''collect object members from incoming things and their bases'''
-        _mz = self._partial(self._mfilter, self._call)
+        _mf = self._mfilter
+        _mz = lambda x: _mf(self._call, x)
         if PY3:
             def _memfilters(thing, mz=_mz, gc=getcls, ci=self._ichain):
                 t = lambda x: not x[0].startswith('mro')
             return self._xtend(
                 self._ichain(self._imap(_memfilters, self._iterable))
             )
+            
+    def extract(self):
+        '''extract object members from incoming things'''
+        with self._context():
+            walk_ = self._extract
+            call_, alt_, wrap_ = self._call, self._alt, self._wrapper
+            return self._xtend(self._ichain(self._imap(
+                lambda x: walk_(call_, alt_, wrap_, x), self._iterable,
+            )))
 
     def members(self):
         '''collect object members from incoming things'''
             return self._xtend(self._ichain(self._imap(
                 self._partial(self._mfilter, self._call), self._iterable,
             )))
-            
-    def extract(self):
-        '''extract object members from incoming things'''
-        with self._context():
-            walk_ = self._walk
-            call_, alt_, wrap_ = self._call, self._altcall, self._wrapper
-            return self._xtend(self._ichain(self._imap(
-                lambda x: walk_(call_, alt_, wrap_, x), self._iterable,
-            )))
 
     def pick(self, *names):
         '''collect object attributes from incoming things by their `*names`'''
     _ireduce = lazier(functools.reduce)
     _islice = lazier(itertools.islice)
     _items = lazier(support.items)
-    _iterz = lazier(iter)
     _join = lazier(itertools.chain)
-    _len = lazier(len)
-    _list = lazier(list)
-    _max = lazier(max)
     _methodcaller = lazier(methodcaller)
-    _min = lazier(min)
-    _next = lazier(next)
     _partial = lazier(functools.partial)
     _range = lazier(support.range)
     _repeat = lazier(itertools.repeat)
     _sample = lazier(sample)
     _shuffle = lazier(shuffle)
     _sleep = lazier(time.sleep)
-    _sorted = lazier(sorted)
     _split = lazier(itertools.tee)
     _starmap = lazier(itertools.starmap)
-    _sum = lazier(sum)
     _truediv = lazier(operator.truediv)
     _zip = lazier(zip)
 
         # current callable
         self._call = lambda x: x
         # current alt callable
-        self._altcall = lambda x: x
+        self._alt = lambda x: x
         # clear wrapper
-        self._wrapper = self._list
+        self._wrapper = list
         # reset postitional arguments
         self._args = ()
         # reset keyword arguments
         # set defaults
         self.unswap()
 
-    ###########################################################################
-    ## iteration ##############################################################
-    ###########################################################################
-
     @property
     def balanced(self):
         '''if queues are balanced'''
         return self.outcount() == self.__len__()
 
-    ###########################################################################
-    ## things clearance #######################################################
-    ###########################################################################
-
     def clear(self):
         '''clear every thing'''
-        return (
-            self.detap().unwrap().dealt().outclear().inclear()._wclear()
-            ._uclear()
-        )
+        self.detap().unwrap().dealt()
+        return self.outclear().inclear()._wclear()._uclear()
 
     ###########################################################################
     ## context rotation #######################################################
 
         @param call: an alternative callable
         '''
-        self._altcall = call
+        self._alt = call
         return self
 
     def detap(self):
     
     def dealt(self):
         '''clear current alternative callable'''
-        self._altcall = lambda x: x
+        self._alt = lambda x: x
         return self
 
     def factory(self, call):
         with self.ctx1():
             return self._xtend(things)
 
-    def preextend(self, things):
+    def prextend(self, things):
         '''
         extend left side of incoming things with `things`
 
         with self.ctx1():
             return self._xtendleft(things)
         
-    extendleft = preextend
+    extendleft = prextend
 
     def outextend(self, things):
         '''
         next_ = self._next
         iterable = self._imap(call, iterable)
         try:
-            while True:
+            while 1:
                 next_(iterable)
         except exception:
             pass
                 self._counter(self._iterable).most_common(1)[0][0]
             )
 
-    def uncommon(self):
-        '''least common incoming thing'''
-        with self._context():
-            return self._append(
-                self._counter(self._iterable).most_common()[:-2:-1][0][0]
-            )
-
-    def frequency(self):
-        '''frequency of each incoming thing'''
-        with self._context():
-            return self._append(self._counter(self._iterable).most_common())
-
     def statrange(self):
         '''statistical range of all incoming things'''
         with self._context():
-            iterz = self._list(self._sorted(self._iterable))
+            iterz = list(self._sorted(self._iterable))
             return self._append(iterz[-1] - iterz[0])
 
     def sum(self, start=0):
         with self._context():
             return self._append(self._contains(self._iterable, thing))
 
+    def frequency(self):
+        '''frequency of each incoming thing'''
+        with self._context():
+            return self._append(self._counter(self._iterable).most_common())
+
     def quantify(self):
         '''how many times call is `True` for incoming things'''
         with self._context():
                 self._imap(self._call, self._iterable)
             ))
 
+    def uncommon(self):
+        '''least common incoming thing'''
+        with self._context():
+            return self._append(
+                self._counter(self._iterable).most_common()[:-2:-1][0][0]
+            )
+
 
 class ReduceMixin(local):
 
         with self._context():
             return self._xtend(merge(*self._iterable))
 
-    def smash(self):
-        '''flatten deeply nested incoming things'''
-        with self._context():
-            return self._xtend(self._smash(self._iterable))
-
-    flatten = smash
-
     def pairwise(self):
         '''every two incoming things as a tuple'''
         with self._context():
             a, b = self._split(self._iterable)
-            next(b, None)
+            self._next(b, None)
             return self._xtend(self._zip(a, b))
 
     def reduce(self, initial=None):
             if initial is None:
                 return self._append(self._ireduce(self._call, self._iterable))
             return self._append(self._ireduce(
-                 self._call, self._iterable, initial,
+                self._call, self._iterable, initial,
             ))
 
     def reduce_right(self, initial=None):
         '''interleave incoming things into one thing'''
         with self._context():
             return self._xtend(self._roundrobin(self._iterable))
+        
+    def smash(self):
+        '''flatten deeply nested incoming things'''
+        with self._context():
+            return self._xtend(self._smash(self._iterable))
+
+    flatten = smash
 
     def zip(self):
         '''

twoq/tests/auto/filtering.py

             class stoog4: #@IgnorePep8
                 name = 'beastly'
                 age = 969
-        test = lambda x: not x.startswith('__')
+        test = lambda x: not x[0].startswith('__')
         value = self.qclass(
             stooges, stoog2, stoog3
         ).tap(test).alt(isclass).wrap(tuple).extract().detap().end(),

twoq/tests/auto/reducing.py

             self.qclass(11, 3, 5, 11, 7, 3, 11).mode().end(), 11,
         )
 
-    def test_uncommon(self):
-        self.assertEqual(
-            self.qclass(11, 3, 5, 11, 7, 3, 11).uncommon().end(), 7,
-        )
-
-    def test_frequency(self):
-        self.assertEqual(
-            self.qclass(11, 3, 5, 11, 7, 3, 11).frequency().end(),
-            [(11, 3), (3, 2), (5, 1), (7, 1)]
-        )
-
     def test_statrange(self):
         self.assertEqual(self.qclass(3, 5, 7, 3, 11).statrange().end(), 8)
 
             self.qclass(None, 0, 'yes', False).tap(bool).quantify().end(), 1,
         )
 
+    def test_uncommon(self):
+        self.assertEqual(
+            self.qclass(11, 3, 5, 11, 7, 3, 11).uncommon().end(), 7,
+        )
+
+    def test_frequency(self):
+        self.assertEqual(
+            self.qclass(11, 3, 5, 11, 7, 3, 11).frequency().end(),
+            [(11, 3), (3, 2), (5, 1), (7, 1)]
+        )
+
 
 class AReduceQMixin(AMathQMixin, ATruthQMixin):
 

twoq/tests/man/filtering.py

             self.qclass(
                 stooges, stoog2, stoog3
             ).tap(
-                lambda x: not x.startswith('__')
+                lambda x: not x[0].startswith('__')
             ).alt(isclass).wrap(tuple).extract().detap().sync(),
             self.assertEqual,
             (('age', 40), ('name', 'moe'), ('age', 50), ('name', 'larry'),

twoq/tests/man/reducing.py

             31.666666666666668,
         )
 
-    def test_uncommon(self):
-        self._false_true_false(
-            self.qclass(11, 3, 5, 11, 7, 3, 11).uncommon(),
-            self.assertEqual,
-            7,
-        )
-
-    def test_frequency(self):
-        self._false_true_false(
-            self.qclass(11, 3, 5, 11, 7, 3, 11).frequency(),
-            self.assertEqual,
-            [(11, 3), (3, 2), (5, 1), (7, 1)],
-        )
-
     def test_statrange(self):
         self._false_true_false(
             self.qclass(3, 5, 7, 3, 11).statrange(),
             self.assertEqual,
             1,
         )
+        
+    def test_uncommon(self):
+        self._false_true_false(
+            self.qclass(11, 3, 5, 11, 7, 3, 11).uncommon(),
+            self.assertEqual,
+            7,
+        )
+
+    def test_frequency(self):
+        self._false_true_false(
+            self.qclass(11, 3, 5, 11, 7, 3, 11).frequency(),
+            self.assertEqual,
+            [(11, 3), (3, 2), (5, 1), (7, 1)],
+        )
 
 
 class MReduceQMixin(MMathQMixin, MTruthQMixin):