title: compose function and functional module
body: <p><a href="http://docs.python.org/release/3.2.2/howto/functional.html#the-functional-module" rel="nofollow noreferrer">Python 3.2 documentation</a> refers to <a href="http://oakwinter.com/code/functional/" rel="nofollow noreferrer">Collin Winter's <code>functional</code> module</a> which contains function <code>compose</code>:</p>
  
  <blockquote>
    <p>The compose() function implements function composition. In other
    words, it returns a wrapper around the outer and inner callables, such
    that the return value from inner is fed directly to outer.</p>
  </blockquote>
  
  <p>Unfortunately, this module hasn't been updated since July 2006; I wonder if there's any replacement available.</p>
  
  <p>For now, I only need <code>compose</code> function. Is the following original <code>functional.compose</code> definition still good for Python 3?</p>
  
  <pre><code>def compose(func_1, func_2, unpack=False):
      """
      compose(func_1, func_2, unpack=False) -&gt; function
  
      The function returned by compose is a composition of func_1 and func_2.
      That is, compose(func_1, func_2)(5) == func_1(func_2(5))
      """
      if not callable(func_1):
          raise TypeError("First argument to compose must be callable")
      if not callable(func_2):
          raise TypeError("Second argument to compose must be callable")
  
      if unpack:
          def composition(*args, **kwargs):
              return func_1(*func_2(*args, **kwargs))
      else:
          def composition(*args, **kwargs):
              return func_1(func_2(*args, **kwargs))
      return composition
  </code></pre>
  
  <p>This <a href="https://stackoverflow.com/questions/2281693/is-it-a-good-idea-to-have-a-syntax-sugar-to-function-composition-in-python">SO question</a> is somewhat related; it asks whether Python should support special syntax for <code>compose</code>.</p>