Function that fixes an argument of another function

Thanks. You were right. I was overthinking it, the following function does the job:

function construct_fixed_f(g, n, val, cache)
    new_f = @inline (x, p) -> begin
        cache2 = get_tmp(cache, x)
        for i in eachindex(cache2)
            if i < n
                cache2[i] = x[i]
            elseif i == n
                cache2[i] = val
            elseif i > n
                cache2[i] = x[i-1]
            end
        end
        return g(cache2, p)
    end
end