ntfromstruct could optionally store type as a field of NamedTuple
scls19fr opened this issue · 8 comments
scls19fr commented
Hello,
In your example
Struct construction, conversion
using NamedTupleTools
julia> struct MyStruct
tally::Int
team::String
end
julia> mystruct = MyStruct(5, "hometeam")
MyStruct(5, "hometeam")
julia> mynamedtuple = ntfromstruct(mystruct)
(tally = 5, team = "hometeam")
it could be useful to have an option for ntfromstruct
function to preserve type name (probably as a Symbol)
julia> mynamedtuple = ntfromstruct(mystruct, keep_type=true)
(type = :MyStruct, tally = 5, team = "hometeam")
Kind regards
JeffreySarnoff commented
hmmm
scls19fr commented
julia> merge((type=Symbol(typeof(mystruct)),), ntfromstruct(mystruct))
(type = :MyStruct, tally = 5, team = "hometeam")
JeffreySarnoff commented
why did you close this?
I have been working on a version that handles both ways.
Jeffrey Sarnoff
… On Dec 31, 2019, at 7:10 AM, scls19fr ***@***.***> wrote:
julia> merge((type=Symbol(typeof(mystruct)),), ntfromstruct(mystruct))
(type = :MyStruct, tally = 5, team = "hometeam")
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
JeffreySarnoff commented
Implemented as an option in version 1 (wip). Thank you.
JeffreySarnoff commented
you are credited in the v1 Readme
scls19fr commented
Sorry @JeffreySarnoff but I don't see a PR or a commit linking to this issue.
JeffreySarnoff commented
It was a suggestion of yours #14
The implementation is in the v1 branch, which is a work in progress. The credit is here (last entry) https://github.com/JeffreySarnoff/NamedTupleTools.jl/blob/v1/README.md#credits
scls19fr commented
ok in the v1 branch!
I didn't understand what you mean by v1.
Thanks @JeffreySarnoff