#!/usr/local/bin/python2 class ExtendableFunction(object): def __init__(self, func): self._base = func self._head = [] self._tail = [] def __call__(self, *args, **kwargs): for func in self._head: func(*args, **kwargs) result = self._base(*args, **kwargs) for func in self._tail: func(*args, **kwargs) return result @property def head(self): return self._head @property def tail(self): return self._tail @property def replica(self): def f(*args, **kwargs): for func in self._head: func(*args, **kwargs) result = self._base(*args, **kwargs) for func in self._tail: func(*args, **kwargs) return result return f e = ExtendableFunction(bool) e.head.append(str) print e(1)