def recursive(accumulate=False):
    """
    Decorator that labels a Pipe method as recursive. This means, that method func will first be called on
    the Pipe's inputs and then on the Pipe itself.
    If accumulate is set to True, then the result from calling the method on a given Pipe will be
    used as input to the next one. If False, then the original arguments will be used when calling
    the method each time.
    """
    def outer(func):

        def wrapper(obj, *args, **kwargs):

            try:
                response = obj.input.__getattribute__(func.__name__)(*args, **kwargs)
            except AttributeError:
                response = None

            if accumulate:
                return func(obj, response)
            else:
                return func(obj, *args, **kwargs)

        return wrapper

    return outer