| 1 | #!/usr/bin/env python |
| 2 | class 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 | |