Reputation: 151
I can initialize an array of tuples with Array{Tuple{Int, Int}}(undef, 10)
.
However, I cannot make it work for named tuples. Does anyone know how I can do this?
Thanks in advance!
Upvotes: 3
Views: 732
Reputation: 69839
This is the way to do it (I understand you want an uninitialized array of NamedTuples
having a concrete type):
julia> Array{NamedTuple{(:a, :b), Tuple{Int64, Float64}}}(undef, 10)
10-element Vector{NamedTuple{(:a, :b), Tuple{Int64, Float64}}}:
(a = 257472272, b = 1.272082044e-315)
(a = 257472272, b = 1.272082044e-315)
(a = 257472272, b = 1.272082044e-315)
(a = 257472272, b = 1.272082044e-315)
(a = 257472272, b = 1.272082044e-315)
(a = 257472272, b = 2.156699073e-315)
(a = 257472272, b = 1.272082044e-315)
(a = 257472272, b = 2.15670018e-315)
(a = 257472272, b = 1.272082044e-315)
(a = 257472272, b = 1.272082044e-315)
julia> Array{NamedTuple{(:a, :b), Tuple{Int64, String}}}(undef, 10)
10-element Vector{NamedTuple{(:a, :b), Tuple{Int64, String}}}:
#undef
#undef
#undef
#undef
#undef
#undef
#undef
#undef
#undef
#undef
Upvotes: 7