def apply_if(predicate, function):
    """apply_if(predicate, function)(val) -> a value or None

    apply_if :: ((a|None -> bool), (a -> b)) -> a|None -> b|None

    If predicate(val) is True or True-like, returns function(val)
    Otherwise returns val as-is.

    WARNING: This is likely to move into funbox.maybe soon.

    >>> contains_a = lambda astr : 'a' in astr
    >>> to_upper = lambda astr : astr.upper()
    >>> strings = ['a', 'b', 'C', 'dear', 'apple', 'rod']
    >>> list(map(apply_if(contains_a, to_upper), strings))
    ['A', 'b', 'C', 'DEAR', 'APPLE', 'rod']
    """
    def pass_if_pf(val):
        return function(val) if predicate(val) else val
    return pass_if_pf