# How do I define a dictionary type for tuples with functions as elements?

**URL:** <https://discourse.julialang.org/t/how-do-i-define-a-dictionary-type-for-tuples-with-functions-as-elements/79038>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 5, 2022, 9:56am UTC](https://discourse.julialang.org/t/how-do-i-define-a-dictionary-type-for-tuples-with-functions-as-elements/79038 "2022-04-05T09:56:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soldalma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/soldalma/32/29388_2.png) [@Soldalma](https://discourse.julialang.org/u/Soldalma)\
**Post date:** [April 5, 2022, 9:56am UTC](https://discourse.julialang.org/t/how-do-i-define-a-dictionary-type-for-tuples-with-functions-as-elements/79038/1 "2022-04-05T09:56:19Z")

</div>

I want to create a dictionary whose entries are 2-tuples where the second element is a function.

One such dictionary would be:

```julia
di1 = Dict(:C => ([:AA], identity))

```

However, its type does not match what I want:

```julia
typeof(di1)
# Dict{Symbol, Tuple{Vector{Symbol}, typeof(identity)}}

```

This is true:

```julia
typeof(identity) <: Function
# true

```

But this is false:

```julia
typeof(di1) <: Dict{Symbol, Tuple{Vector{Symbol}, <:Function}}
# false

```

So if define:

```julia
di2 = Dict(:C => ([:AA], x -> x))

```

I get:

```julia
typeof(di2) <: typeof(di1)
# false

```

How can I define a type for `Dict(:C => ([:AA], f))` so that it works for any function `f`?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [April 5, 2022, 10:06am UTC](https://discourse.julialang.org/t/how-do-i-define-a-dictionary-type-for-tuples-with-functions-as-elements/79038/2 "2022-04-05T10:06:45Z")

</div>

If you define such a dict with two entries, you get the less specific type

```julia
julia> typeof(Dict(:C => ([:AA], identity), :D => ([:AA], map)))
Dict{Symbol, Tuple{Vector{Symbol}, Function}}

```

and you can define your `di1` explicitly with this type:

```julia
julia> di1 = Dict{Symbol, Tuple{Vector{Symbol}, Function}}(:C => ([:AA], identity))
Dict{Symbol, Tuple{Vector{Symbol}, Function}} with 1 entry:
  :C => ([:AA], identity)

```

Is this sufficient for your needs?

---

<div class="post-metadata">

**Author:** ![Soldalma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/soldalma/32/29388_2.png) [@Soldalma](https://discourse.julialang.org/u/Soldalma)\
**Post date:** [April 6, 2022, 12:00am UTC](https://discourse.julialang.org/t/how-do-i-define-a-dictionary-type-for-tuples-with-functions-as-elements/79038/3 "2022-04-06T00:00:46Z")

</div>

> [@GunnarFarneback](#):
>
> `Dict{Symbol, Tuple{Vector{Symbol}, Function}}`

It works. Thanks.
