# Storing a dispatched method for later use

**URL:** <https://discourse.julialang.org/t/storing-a-dispatched-method-for-later-use/5404>\
**Category:** General Usage\
**Created:** [August 16, 2017, 4:30am UTC](https://discourse.julialang.org/t/storing-a-dispatched-method-for-later-use/5404 "2017-08-16T04:30:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Post date:** [August 16, 2017, 4:30am UTC](https://discourse.julialang.org/t/storing-a-dispatched-method-for-later-use/5404/1 "2017-08-16T04:30:47Z")

</div>

Suppose I have several method definitions with the same function name. Is it possible to dispatch a method for specific arguments, store the dispatched function, and use it later?

For example, suppose I have types and methods for the types as follows:

```julia
abstract type MyAbs end

struct MyType1 <: MyAbs end
struct MyType2 <: MyAbs end
struct MyType3 <: MyAbs end
struct MyType4 <: MyAbs end

myfun(i::Int, m::MyType1) = ...
myfun(i::Int, m::MyType2) = ...
myfun(i::Int, m::MyType3) = ...
myfun(i::Int, m::MyType4) = ...

```

Now, I want to do something like this:

```julia
mvec = [MyType1(), MyType2(), MyType3(), MyType4()] # Vector{MyAbs}

for m = mvec
    f = (dispatch myfun for typeof(m)) # store dispatched myfun in f
    for i = 1:100
        f(i, m) # execute dispatched method without dispatching it every iteration
    end   
end

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 16, 2017, 4:50am UTC](https://discourse.julialang.org/t/storing-a-dispatched-method-for-later-use/5404/2 "2017-08-16T04:50:05Z")

</div>

> [@wsshin](#):
>
> Suppose I have several method definitions with the same function name. Is it possible to dispatch a method for specific arguments, store the dispatched function, and use it later?

Use a function barrier?
