# Coerce type of elements in an empty concatenation

**URL:** <https://discourse.julialang.org/t/coerce-type-of-elements-in-an-empty-concatenation/36045>\
**Category:** General Usage\
**Created:** [March 16, 2020, 4:01pm UTC](https://discourse.julialang.org/t/coerce-type-of-elements-in-an-empty-concatenation/36045 "2020-03-16T16:01:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [March 16, 2020, 4:01pm UTC](https://discourse.julialang.org/t/coerce-type-of-elements-in-an-empty-concatenation/36045/1 "2020-03-16T16:01:48Z")

</div>

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-repl
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?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [March 16, 2020, 4:09pm UTC](https://discourse.julialang.org/t/coerce-type-of-elements-in-an-empty-concatenation/36045/2 "2020-03-16T16:09:27Z")

</div>

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