title: How to add functions
body: <p>I have looked all over but it is a hard topic to search for without lots of noise. I want to do something like this:</p>
  
  <pre><code>def f(arg):
    return arg * arg
  
  def add(self, other):
    return self * other
  
  f.__add__ = add
  
  cubefunction = f + f
  </code></pre>
  
  <p>But I get errors on the assignment to cubefunction like:</p>
  
  <pre><code>TypeError: unsupported operand type(s) for +: 'function' and 'function'
  </code></pre>
  
  <p>Is there no function algebra possible in python or am I just making a dumb mistake?</p>
  
  <p>edit: much later, I was reading Python's official intro to functional programming (<a href="http://docs.python.org/howto/functional.html" rel="noreferrer">http://docs.python.org/howto/functional.html</a>), and towards the bottom it references a third party package "functional" (<a href="http://oakwinter.com/code/functional/documentation/" rel="noreferrer">http://oakwinter.com/code/functional/documentation/</a>), which can compose functions, ie:</p>
  
  <pre><code>&gt;&gt;&gt; from functional import compose
  &gt;&gt;&gt; def add(a, b):
  ...     return a + b
  ...
  &gt;&gt;&gt; def double(a):
  ...     return 2 * a
  ...
  &gt;&gt;&gt; compose(double, add)(5, 6)
  22
  </code></pre>