title: Cascading functions in Python using reduce and decorators
body: <p>I have a method called <code>render</code> that is actually implemented by a subclass and called like this:</p>
  
  <pre><code>class MyClass(object):
  
      def __call__(self, *args, **kwargs):
  
          api_response = self.render(*args, **kwargs)
  
          return api_response
  
      def render(self, *args, **kwargs):
          """ This method is implemented by a subclass."""    
          raise NotImplementedError
  
      def cascade_callables():
          print 'Ask awesome people at stackoverflow for the solution to this problem.'
  </code></pre>
  
  <p>I have a list of callables <code>[c1, c2, c3]</code>. I want to do something like this inside the <code>cascade_callables</code> method which should be something like this:</p>
  
  <pre><code>def cascade_callables():
      callables = [c1, c2, c3]
      callables.append(self.render)
      self.render = reduce(some_decorator_that_accepts_two_functions, callables)
  </code></pre>
  
  <p>So essentially, I am trying my <code>render</code> to work like this without modifying the actual implementation:</p>
  
  <pre><code>c1(*args, **kwargs)
  c2(*args, **kwargs)
  c3(*args, **kwargs)
  render(*args, **kwargs)
  </code></pre>
  
  <p>I tried something like this to work as the decorator for me that I can use in <code>reduce</code>:</p>
  
  <pre><code>def cascade_modifiers(modifier1, modifier2):
  
      def cascaded_modifier(self, *args, **kwargs):
  
          modifier1(self, *args, **kwargs)
          modifier2(self, *args, **kwargs)
  
      return cascaded_modifier
  </code></pre>
  
  <p>But I got this:</p>
  
  <pre><code>TypeError: cascaded_modifier() takes at least 1 argument (0 given)
  </code></pre>
  
  <p>What is the best approach to solve this problem in Python 2.7 using the paradigm that I have tried explaining in this question?</p>