# Chain function calls based on array

**URL:** <https://discourse.julialang.org/t/chain-function-calls-based-on-array/20775>\
**Category:** General Usage\
**Tags:** metaprogramming\
**Created:** [February 14, 2019, 5:26am UTC](https://discourse.julialang.org/t/chain-function-calls-based-on-array/20775 "2019-02-14T05:26:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pazzo83](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pazzo83/32/232_2.png) [@pazzo83](https://discourse.julialang.org/u/pazzo83)\
**Post date:** [February 14, 2019, 5:26am UTC](https://discourse.julialang.org/t/chain-function-calls-based-on-array/20775/1 "2019-02-14T05:26:18Z")

</div>

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

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

```

… translate:

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

```

into:

```julia
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](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):

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

```

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [February 14, 2019, 6:44am UTC](https://discourse.julialang.org/t/chain-function-calls-based-on-array/20775/2 "2019-02-14T06:44:03Z")

</div>

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