How to make a named tuple from a dictionary?

map and collect are also not strictly necessary

namedtuple(x) = x
namedtuple(d::Dict) = (; (Symbol(k) => namedtuple(v) for (k,v) in d)...)

dind=Dict('A'=>1,'B'=>d,'C'=>3)
julia> namedtuple(dind)
(C = 3, A = 1, B = (c = 7, b = 6, a = 5))
3 Likes