Reshape of numbers. Is it a bad idea?

I have a function when I want to be sure one parameter is a vector, even if it is given as number.

I thought to use reshape(myInt,1) but notice reshape of numbers is not in Base.
No problem, I can add a method to handle it:

import Base.reshape
function reshape(x::Number, dims...) where {T <: Number}
   x = [x]
   reshape(x,dims)
end

But, as it is not in Base, I wonder if it is a good approach or it is intentionally left it out from Base.

I would just do something like

ensure_vector(v::AbstractVector) = v
ensure_vector(x::Number) = [x] # consider SVector(x), depending on context
1 Like