Is there an easy way in base Julia to create a NamedTuple with all the fields except some particular ones? Currently I have the following, but I’m wondering if I’m missing something obvious. I’m calling it delete as it seems to do what delete! does with Dicts, but not in-place.
"""
delete(nt::NamedTuple, fieldnames)
Remove the given fields from `nt`, returning a new `NamedTuple`
"""
function delete(nt::NamedTuple, fieldnames...)
(; filter(p->first(p) ∉ fieldnames, collect(pairs(nt)))...)
end
The collect is necessary because apparently filter on pairs returns a Dict, which loses ordering information.