# Multiple dispatch with Union of parametric types

**URL:** <https://discourse.julialang.org/t/multiple-dispatch-with-union-of-parametric-types/51656>\
**Category:** New to Julia\
**Tags:** question, dispatch\
**Created:** [December 11, 2020, 9:39am UTC](https://discourse.julialang.org/t/multiple-dispatch-with-union-of-parametric-types/51656 "2020-12-11T09:39:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xyz1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xyz1/32/19984_2.png) [@xyz1](https://discourse.julialang.org/u/xyz1)\
**Post date:** [December 11, 2020, 9:39am UTC](https://discourse.julialang.org/t/multiple-dispatch-with-union-of-parametric-types/51656/1 "2020-12-11T09:39:03Z")

</div>

Hi, I have a problem with multidispatch. I have a lot of functions defined that take 2 parameters _a_ and _b_. These may be a vector and a dict, a dict and an int etc. Or e.g. Union{Any, Vector}.  
It all seemed to work well until I decided to add a set of functions where any of the parameters is an Array (not Vector). I believe this must be dispatched with parameters so I changed all Vectors to Array{T,1}.

But with the Union type the dispatch doesn’t do what I’d like it to, see example:

```julia
d1 = Dict("A" => 1)
d2 = Dict("B" => 2)
d3 = Dict("C" => 3)

function x(a::Array{T,N}, b::Dict) where {T,N}
    throw(DomainError("Do not support any arrays!"))
end

function x(a::Union{Any,Array{T,1}}, b::Dict) where T
    return 1
end

x([d1,d2], d3)

```

where It throws the DomainError from the first function but I want it to return “1” because [d1,d2] is a Vector! Thanks!

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [December 11, 2020, 10:01am UTC](https://discourse.julialang.org/t/multiple-dispatch-with-union-of-parametric-types/51656/2 "2020-12-11T10:01:16Z")

</div>

1. `Vector` is an alias for `Array{T, 1}`, so it doesn’t matter how you write it.
2. `Union{Any, Vector{T}}` is `Any`, so you lost `Vector` specialization.

This is working

```julia
function x(a::Array{T,N}, b::Dict) where {T,N}
    throw(DomainError("Do not support any arrays!"))
end

function x(a, b::Dict)
    return 1
end

function x(a::Vector{T}, b::Dict) where T
    return 1
end

julia> x([d1,d2], d3)
1

```
