# Mapping all methods of a module into a Dictionary

**URL:** <https://discourse.julialang.org/t/mapping-all-methods-of-a-module-into-a-dictionary/53179>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 11, 2021, 10:11pm UTC](https://discourse.julialang.org/t/mapping-all-methods-of-a-module-into-a-dictionary/53179 "2021-01-11T22:11:48Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![djholiver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djholiver/32/50470_2.png) [@djholiver](https://discourse.julialang.org/u/djholiver)\
**Post date:** [January 12, 2021, 1:28pm UTC](https://discourse.julialang.org/t/mapping-all-methods-of-a-module-into-a-dictionary/53179/3 "2021-01-12T13:28:54Z")

</div>

Hi,

Many thanks for your reply @pixel27 - when I paste in the code:

```julia
using StatsBase

d = Dict{String,Function}()

functions = names(StatsBase, all= false, imported = false)

for f in functions
 
   # func = f
   if getfield(StatsBase, f) isa Function
        d[string(f)] = getfield(StatsBase, f) 
    end
end

I get the following error:

UndefVarError: findat not defined

Stacktrace:
 [1] top-level scope at .\In[44]:11
 [2] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

```

where line 11 is the “isa” line. Did you get the same? I’m using Julia 1.5.3

The end state for this is create arrays of function, grouped around the common variable (vector) set they all share e.g. (assuming d now populated):

```julia
d = Dict{String,Function}()
computeNames1 = FunctionWrangler([d["Mean"], d["percentile"]])
computeNames2 = FunctionWrangler([d["Mean"]])
computeSets = [computeNames1 , computeNames2] 

vector1 = [i for i in 1:10]
vector2 = [i for i in 10:20]

vectorGrouping = [vector1,vector2]
computeSetIncrement = 1
Threads.@threads for v in vectorGrouping
    result = zeros(Float64, length(computeSets[computeSetIncrement]))
     smap!(result , computeSets[computeSetIncrement], v)
    computeSetIncrement += 1
end

```

using the [FunctionWranglers.jl](https://discourse.julialang.org/t/ann-functionwranglers-jl-fast-inlined-execution-of-arrays-of-functions/48770) package to wrap the function array and then execute each group in parallel. Since I wasn’t sure if it is possible to execute functions in parallel in a thread safe way when acting on different datasources (closer to the [Actor.jl](https://github.com/JuliaActors/Actors.jl) model) I assumed a reference to the method would be required.

Note that an alternative to the above would be to bring the threads into the loop to execute over the computesets in parallel and and / or the vectorGrouping.

@tisztamo , @pbayer - does this use case look valid for your respective packages? My need is to be able to dynamically group methods and dispatch against common data as above, but I don’t think this is a unique scenario so interested in your thoughts on how to implement.

Regards

---

_[View the full topic](https://discourse.julialang.org/t/mapping-all-methods-of-a-module-into-a-dictionary/53179)._
