Hmm,
I have an empty Vector of MutableNamedTuples with a specific signature, ie if the array has a single element, then I can recover the keys of the underlying NamedTuple by inspecting the element.
But what if the array is empty ? The information appears to be there, since eltype() will indicate the mutableNamedTuple signature, but I don’t know how to access the keys from there.
The extra level of indiraction is part of the problem. A MutableNamedTuple is declared as :
struct MutableNamedTuple{N,T <: Tuple{Vararg{<:Ref}}}
nt::NamedTuple{N, T}
end
Calling something like
getfield(eltype(empty_array), 1)
returns T<:Tuple{Vararg{Ref}}, which isn’t what I want.
Is there a way to get the keys of the underlying NamedTuple in a straightforward manner ? I’ve not been able to find a related topic, but I might not know the right keyword.
(I imagine it’s possible by inspecting types in the AST, but that seems like overkill for my simple needs).
The reason I encountered this issue that I wanted to preallocate a Tables-like structure of these Tuples, which needs the key names, but that table might grow and I don’t want to have to check indexes with the preallocated values, so would rather keep the table empty and sizehint! it. Of course, I could just preallocate, declare one element, then empty! the vector and I believe that’d solve my problem, but I’m still curious regarding my question.