Creates a validator that runs the given validator on every item in a list
    or other collection. The validator can mutate the values.

    Any raised errors will be collected into a single ``Invalid`` error. Their
    paths will be replaced with the index of the item. Will raise an error if
    the input value is not iterable.

def List(validator):
    """
    Creates a validator that runs the given validator on every item in a list
    or other collection. The validator can mutate the values.

    Any raised errors will be collected into a single ``Invalid`` error. Their
    paths will be replaced with the index of the item. Will raise an error if
    the input value is not iterable.
    """
    @wraps(List)
    def built(value):
        if not hasattr(value, '__iter__'):
            raise Error("Must be a list")

        invalid = Invalid()
        for i, item in enumerate(value):
            try:
                value[i] = validator(item)
            except Invalid as e:
                for error in e:
                    error.path.insert(0, i)
                    invalid.append(error)
            except Error as e:
                e.path.insert(0, i)
                invalid.append(e)

        if len(invalid):
            raise invalid
        return value
    return built