# Passing Some Arguments To A Function That Is An Argument To Some Other Function

**URL:** <https://discourse.julialang.org/t/passing-some-arguments-to-a-function-that-is-an-argument-to-some-other-function/62762>\
**Category:** New to Julia\
**Created:** [June 11, 2021, 8:30pm UTC](https://discourse.julialang.org/t/passing-some-arguments-to-a-function-that-is-an-argument-to-some-other-function/62762 "2021-06-11T20:30:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmdenis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cmdenis/32/211517_2.png) [@cmdenis](https://discourse.julialang.org/u/cmdenis)\
**Post date:** [June 11, 2021, 8:30pm UTC](https://discourse.julialang.org/t/passing-some-arguments-to-a-function-that-is-an-argument-to-some-other-function/62762/1 "2021-06-11T20:30:36Z")

</div>

Hello,

I am wondering whether there is a nice way of passing arguments to a function that is itself an argument to a function. So, currently, I have a piece of code that looks like this:

```julia
function func_manip(func)
    # Uses the function in some way
end

function linear_func(x, a)
    return x*a
end

for i in 0:10
    f(x) = linear_func(x, i)
    func_manip(f)
end

```

My guts tells me that this is not the most elegant way of doing this. I was thinking that maybe there would be a way of doing something where instead of defining the `f` function, I could simply specify which arguments I pass with the inputted function in `func_manip`. So something like:

```julia
function func_manip(func)
    # Uses the function in some way
end

function linear_func(x, a)
    return x*a
end

for i in 0:10
    func_manip(f(::, i))
end

```

Otherwise, I thought about adding another argument to the `func_manip` that I would be plugging into `func` inside `func_manip`, but for the precise application I was working on, it was making the code a bit crowded. Maybe there is another method that essentially does the same thing.  
Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [June 11, 2021, 8:38pm UTC](https://discourse.julialang.org/t/passing-some-arguments-to-a-function-that-is-an-argument-to-some-other-function/62762/2 "2021-06-11T20:38:21Z")

</div>

An anonymous function works very nicely in this case:

```julia
julia> function func_manip(func)
           @show func(1)
       end
func_manip (generic function with 1 method)

julia> function linear_func(x, a)
           return x*a
       end
linear_func (generic function with 1 method)

julia> for i in 0:10
           func_manip(x -> linear_func(x, i))
       end

```

where `x -> linear_func(x, i)` creates a new function of one variable and _closes over_ the variable `i` (a.k.a a _closure_).

---

<div class="post-metadata">

**Author:** ![cmdenis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cmdenis/32/211517_2.png) [@cmdenis](https://discourse.julialang.org/u/cmdenis)\
**Post date:** [June 14, 2021, 6:42pm UTC](https://discourse.julialang.org/t/passing-some-arguments-to-a-function-that-is-an-argument-to-some-other-function/62762/3 "2021-06-14T18:42:28Z")

</div>

I like that! Thanks!
