Chain function calls based on array

metaprogramming

#1

I am trying to figure out a way to, given:

addtest(a, b) = a+ b
test = [1, 2, 3, 4]
y = 10

… translate:

for a in test
    y += addtest(a, y)
end

into:

y = addtest(test[1], y)
y = addtest(test[2], y)
etc..

The reason why is I am using the Lazy package (https://github.com/MikeInnes/Lazy.jl) to chain function calls together, and the real situation I am using it in requires some way to apply a function N times with the values in an array of length N as an argument to that function each time it is called. In other words, something like this (which doesn’t work):

@as x 10 begin
        for f = test
            addtest(f, x)
        end
end

#2

I’m not sure, but is foldl((y, x) -> addtest(x, y) + y, test; init=10) what you need?