better living through software
JeffreySarnoff opened this issue · 1 comments
JeffreySarnoff commented
Hi @cscherrer @KristofferC @kmsquire @pdeffebach @scls19fr @sethaxen @tkf.
I've been working on NamedTupleTools#v1, intending to provide a solid, effective, consistent, performant, robust and comfortable API. The #v1 README is currentish with the source code.
Your thoughts, insights, perspectives, and suggestions are most welcome.
Best, Jeffrey Sarnoff
tkf commented
For prototype
, have a look at ConstructionBase.constructorof
. I think it is more efficient and has more sane behavior:
julia> t = NamedTuple{(:a,)}
NamedTuple{(:a,),T} where T<:Tuple
julia> t(1)
(a = 1,)
julia> t((1,))
(a = 1,)
julia> t(((1,),))
(a = (1,),)
julia> c = constructorof(typeof((a=1,)))
ConstructionBase.NamedTupleConstructor{(:a,)}()
julia> c(1)
(a = 1,)
julia> c((1,))
(a = (1,),)
ConstructionBase.jl also provides setproperties
which can be used as setproperties(nt; :b => "cat")
instead of setproperty(nt, :b, "cat")
. For resetproperty
, why not just do (; nt..., :b => "cat")
?