示例#1
0
文件: liste.py 项目: jldupont/pyfnc
 def filter(self, f, *args, **kwargs):
     """
     Keeps only the elements where f(el)==True
     """
     _f=partial(f, *args, **kwargs)
     
     self[:]=filter(_f, self)
     return self
示例#2
0
文件: liste.py 项目: jldupont/pyfnc
 def find(self, f, *args, **kwargs):
     """
     Returns the first element matching the predicate 'f' else returns None
     """
     _f=partial(f, *args, **kwargs)
     
     for el in self:
         if _f(el):
             return el
示例#3
0
文件: liste.py 项目: jldupont/pyfnc
 def map(self, f, *args, **kwargs):
     """
     Applies 'f' to all elements
     
     returns 'self'
     """
     _f=partial(f, *args, **kwargs)
     
     self[:]=map(_f, self)
     return self
示例#4
0
文件: dic.py 项目: jldupont/pyfnc
 def count(self, f, *args, **kwargs):
     """
     Count pairs matching predicate
     """
     _f=partial(f, *args, **kwargs)
     
     count=0
     for k,v in self.items():
         if _f(k,v):
             count=count+1
     return count
示例#5
0
文件: dic.py 项目: jldupont/pyfnc
    def any(self, f, *args, **kwargs):
        """
        Applies 'f' to all [k:v] pairs and expects at least 1 'True' result
        """
        _f = partial(f, *args, **kwargs)

        for x, y in self.items():
            if _f(x, y):
                return True

        return False
示例#6
0
文件: dic.py 项目: jldupont/pyfnc
    def all(self, f, *args, **kwargs):
        """
        Applies 'f' to all [k:v] pairs and expects 'True' for all results
        """
        _f = partial(f, *args, **kwargs)

        for x, y in self.items():
            if not _f(x, y):
                return False

        return True
示例#7
0
文件: liste.py 项目: jldupont/pyfnc
    def all(self, f, *args, **kwargs):
        """
        Applies 'f' to all elements and expects 'True' for all results
        """
        _f=partial(f, *args, **kwargs)

        for el in self:
            if not _f(el):
                return False

        return True
示例#8
0
文件: liste.py 项目: jldupont/pyfnc
 def count(self, f, *args, **kwargs):
     """
     Counts elements in the list matching 'f' predicate
     """
     _f=partial(f, *args, **kwargs)
     
     count=0
     for el in self:
         if _f(el):
             count=count+1
     return count
示例#9
0
文件: liste.py 项目: jldupont/pyfnc
    def any(self, f, *args, **kwargs):
        """
        Applies 'f' to all elements and expects at least 1 'True' result
        """
        _f=partial(f, *args, **kwargs)

        for el in self:
            if _f(el):
                return True

        return False
示例#10
0
文件: dic.py 项目: jldupont/pyfnc
 def map(self, f, *args, **kwargs):
     """
     Applies 'f' for each [k,v] pair - 'f' must return (k,v) pair
     """
     #_f = self._f(f, *args, **kwargs)
     _f=partial(f, *args, **kwargs)
     
     d=dic()
     for k,v in self.items():
         nk, nv=_f(k,v)
         d[nk]=nv
     self.clear()
     return self.clear().update(d)
示例#11
0
文件: liste.py 项目: jldupont/pyfnc
 def tee(self, f, *args, **kwargs):
     """
     Calls 'f' on self, returns self, keeps 'last value'
     """
     self.last_value=partial(f, *args, **kwargs)(self)
     return self
示例#12
0
文件: liste.py 项目: jldupont/pyfnc
 def do(self, f, *args, **kwargs):
     """
     Calls 'f' on self, returns result
     """
     return partial(f, *args, **kwargs)(self)
示例#13
0
文件: liste.py 项目: jldupont/pyfnc
 def reduce(self, f, *args, **kwargs):
     """
     Reduce
     """
     _f=partial(f, *args, **kwargs)
     return reduce(_f, self)