def pipe(*funcs, name=None, doc=None):
    """Create a pipeline of functions. The first function is passed the original arguments, and
    the remaining functions take as single argument the return value of the previous function.

        P = func.pipe(f, g, h)
        P(x)  # equivalent to... h(g(f(x)))

    The name and docstring of the newly created function can be given through the 'name' and
    'doc' keyword-only arguments.
    """
    def pipe_func(*args, **kwargs):
        ifuncs = iter(funcs)
        result = next(ifuncs)(*args, **kwargs)
        for func in ifuncs:
            result = func(result)
        return result

    pipe_func.__name__ = name or "pipe({})".format(", ".join(f.__name__ for f in funcs))
    pipe_func.__doc__ = doc
    return pipe_func