Coerce type of elements in an empty concatenation

I have an array of vectors of a given type, that I want to concatenate into a single vector of the same type. vcat is normally good for this, but there is a problem if the array of vectors results to be empty:

julia> a = Vector{Vector{Int}}()
0-element Array{Array{Int64,1},1}

julia> vcat(a...) # I wanted an `Array{Int, 1}` but...
0-element Array{Any,1}

Of course, this is because the last line is equivalent to vcat(), and the function has no way to know what I wanted.

I could use a condition (e.g. isempty(a) ? Int[] : vcat(a...)). But maybe there is a smarter way?

reduce(vcat, a, init = Int[])

2 Likes