def _extract(cls, truth, subcall, transform, iterable): ''' collect members of things @param call: "Truth" filter @param truth: second "Truth" filter @param iterable: an iterable ''' def members(): f, s, t, i = truth, subcall, transform, iterable d, w, g, e = dir, cls._extract, getattr, AttributeError test = lambda x: x.startswith('__') or x.startswith('mro') for k in filterfalse(test, d(i)): try: v = g(i, k) except e: pass else: if s(v): yield k, t(w(f, s, t, v)) else: yield k, v for member in ifilter( truth, members(), ): yield member
def partition(self): ''' split incoming things into `True` and `False` things based on results of call ''' list_, call_ = list, self._call with self._context(): falsy, truey = tee(self._iterable) return self._xtend(iter([ list_(filterfalse(call_, falsy)), list_(ifilter(call_, truey)), ]))
def _mfilter(cls, call, iterable): ''' filter members of things @param call: "Truth" filter @param iterable: an iterable ''' def members(): #@IgnorePep8 itrbl, get_, AttributeError_ = iterable, getattr, AttributeError test = lambda x: x.startswith('__') or x.startswith('mro') for key in filterfalse(test, dir(iterable)): try: thing = get_(itrbl, key) except AttributeError_: pass else: yield key, thing for i in ifilter(call, members()): yield i
def find(self): '''first incoming thing for which call is `True`''' with self._context(): return self._append( next(ifilter(self._call, self._iterable)) )
def filter(self): '''incoming things for which call is `True`''' with self._context(): return self._xtend(ifilter(self._call, self._iterable))
def compact(self): '''strip "untrue" things from incoming things''' with self._context(): return self._iter(ifilter(truth, self._iterable))