def listify(fn=None, wrapper=list):
def listify_return(fn):<EOL><INDENT>@wraps(fn)<EOL>def listify_helper(*args, **kw):<EOL><INDENT>return wrapper(fn(*args, **kw))<EOL><DEDENT>return listify_helper<EOL><DEDENT>if fn is None:<EOL><INDENT>return listify_return<EOL><DEDENT>return listify_return(fn)<EOL>
A decorator which wraps a function's return value in ``list(...)``.

Useful when an algorithm can be expressed more cleanly as a generator but
the function should return an list.

Example::

    >>> @listify
    ... def get_lengths(iterable):
    ...     for i in iterable:
    ...         yield len(i)
    >>> get_lengths(["spam", "eggs"])
    [4, 4]
    >>>
    >>> @listify(wrapper=tuple)
    ... def get_lengths_tuple(iterable):
    ...     for i in iterable:
    ...         yield len(i)
    >>> get_lengths_tuple(["foo", "bar"])
    (3, 3)