# How to dispatch on an SVector?

**URL:** <https://discourse.julialang.org/t/how-to-dispatch-on-an-svector/117855>\
**Category:** General Usage\
**Tags:** question, package, staticarrays\
**Created:** [August 5, 2024, 7:23pm UTC](https://discourse.julialang.org/t/how-to-dispatch-on-an-svector/117855 "2024-08-05T19:23:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 5, 2024, 7:23pm UTC](https://discourse.julialang.org/t/how-to-dispatch-on-an-svector/117855/1 "2024-08-05T19:23:38Z")

</div>

How can I dispatch on an SVector?

Not working:

```julia
function plot2d(pos::Union{Vector, SVector}, reltime=0.0; kwargs...)
    plot2d__(pos, reltime; kwargs...)
end

```

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 5, 2024, 7:26pm UTC](https://discourse.julialang.org/t/how-to-dispatch-on-an-svector/117855/2 "2024-08-05T19:26:31Z")

</div>

What’s happening?

```julia-repl
julia> g(x::Union{Vector, SVector}) = x
g (generic function with 1 method)

julia> g(SVector(1,1,1))
3-element SVector{3, Int64} with indices SOneTo(3):
 1
 1
 1

```

(you may want `AbstractVector` instead of the Union)

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [August 5, 2024, 7:37pm UTC](https://discourse.julialang.org/t/how-to-dispatch-on-an-svector/117855/3 "2024-08-05T19:37:12Z")

</div>

Using AbstractVector solved my issue. Thank you!
