def apply_rule(operator, pattern, replacement):
    """
    Replace the first occurrence of ``pattern`` by ``replacement``
    in ``operator``
    """
    new_op = operator.match_first(pattern)
    if new_op is None:
        return None
    return new_op.replace_first("generic", replacement)