How to convert Vector{Any} to a narrower type?

Consider the following Julia code

julia> a = Any[1, 2, 3.0]
3-element Vector{Any}:
 1
 2
 3.0

julia> map(x->x, a)
3-element Vector{Real}:
 1
 2
 3.0

Here I abused map to convert an array of Any to the narrowest type Real that all elements belong to. Is there a less hacky way to do this, while retaining the automatic detection of actual types inside the array?

1 Like

You can broadcast identity.

4 Likes