JeffreySarnoff/NamedTupleTools.jl

ntfromstruct could optionally store type as a field of NamedTuple

scls19fr opened this issue · 8 comments

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

julia> merge((type=Symbol(typeof(mystruct)),), ntfromstruct(mystruct))
(type = :MyStruct, tally = 5, team = "hometeam")

Implemented as an option in version 1 (wip). Thank you.

you are credited in the v1 Readme

Sorry @JeffreySarnoff but I don't see a PR or a commit linking to this issue.

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

ok in the v1 branch!
I didn't understand what you mean by v1.
Thanks @JeffreySarnoff