is there a way to create array of Any?
Here are two ways to create an array of Any initialized with the named tuple (;some=missing):
fill!(Vector{Any}(undef, 10), (;some=missing)) # fill! returns its first argumentAny[(;some=missing) for _ in 1:10]These forms are not interchangeable when the value of the filling expression is mutable. The first with the fill! expression will use the same value for all elements. The second with the array comprehension will create a separate value for each element. For example, if the value expression is [], the first creates one empty mutable array used in all elements, and the second creates a separate empty mutable array for each element.
@allocated fill!(Vector{Any}(undef, 10), []) # 176 (bytes allocated)@allocated Any[[] for _ in 1:10] # 432 (bytes allocated)Why
Vector{Any}((; some=missing), 10)fails?
The expression Vector{Any}((; some=missing), 10) fails because no method is defined for this case.
Constructor methods are only defined (as of Julia 1.12.0) for
Here is a try to define one:
Vector{T}(value::V, n) where {T, V <: T} = fill!(Vector{T}(undef, n), value)
With this definition, the expression Vector{Any}((; some=missing), 10) works.