How to specify a type of Vector, SVector, OR Tuple of a certain type, such as Int?

I’d like the function to take a Vector, an SVector or Tuple of certain eltype, and unspecified length, what is the most concise type qualifier?

You probably want Union{AbstractVector{T}, Tuple{Vararg{T}}} where {T}. If you need to write this more often, you can also create an alias:

VectorLike{T} = Union{AbstractVector{T}, Tuple{Vararg{T}}}

and then dispatch on that.

1 Like

Thanks @simeonschaub Btw, what is the most concise way of converting any one of them to an SVector{T} ?

Just SVector{length(x), T}(x) should work, but note that this won’t be type stable for Vectors.

1 Like