Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better living through software #20

Open
JeffreySarnoff opened this issue Mar 17, 2020 · 1 comment
Open

better living through software #20

JeffreySarnoff opened this issue Mar 17, 2020 · 1 comment

Comments

@JeffreySarnoff
Copy link
Owner

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
Copy link
Contributor

tkf commented Mar 17, 2020

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")?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants