title: Is there a library function in Python to turn a generator-function into a function returning a list?
body: <p>A number of times I've thought that generator style can be more direct that returning a list, for example,</p>
  
  <pre><code>def foo(input_array):
      for x in input_array:
          yield processed(x)
  </code></pre>
  
  <p>vs.</p>
  
  <pre><code>def bar(input_array):
      accumulator = []
      for x in input_array:
          accumulator.append(processed(x))
      return accumulator
  </code></pre>
  
  <p>(okay, if it were really that simple, I'd write <code>map</code>, but you get the point: the generator version is cleaner). However, a return type of a generator is not always desired. Is there a built-in decorator that I can use to change <code>foo</code> into a function returning a list or tuple? The way I'd write it myself is,</p>
  
  <pre><code>import functools
  
  def transform_return_value(transformer):
      def inner(f):
          @functools.wraps(f)
          def new_f(*argv, **kwargs):
              return transformer(f(*argv, **kwargs))
          return new_f
      return inner
  
  @transform_return_value(list)
  def foo(input_array):
      for x in input_array:
          yield processed(x)
  </code></pre>