MCPcopy Create free account
hub / github.com/ActiveState/code / chainfunc

Class chainfunc

recipes/Python/498271_chaexecutifunctions_using/recipe-498271.py:2–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#!/usr/bin/env python
2class chainfunc(list):
3 def __init__(self):
4 self.res = []
5 def append(self, func, *args, **kw):
6 super(self.__class__, self).append([func,args,kw])
7 def __call__(self):
8 for (fn, args, kw) in self:
9 retval = (fn.__name__, fn(*args, **kw))
10 self.res.append(retval)
11 yield retval
12
13 def ANDoperation(self):
14 state = reduce(lambda x,y: x and y, [bool for id,bool in self.res])
15 return state
16 and_operation = property(fget=ANDoperation)
17
18 def ORoperation(self):
19 state = reduce(lambda x,y: x or y, [bool for id,bool in self.res])
20 return state
21 or_operation = property(fget=ORoperation)
22
23# some sample functions
24

Callers 1

recipe-498271.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected