Closed cstjean closed 5 years ago
Yes! You need to overload Setfield.setproperties(obj, patch::NamedTuple)
. In the next few days/weeks this is moved to the tiny dependency ConstructionBase, see also https://github.com/JuliaObjects/ConstructionBase.jl/pull/1
So in future you only need to depend on ConstructionBase and overload ConstructionBase.setproperties(obj, patch::NamedTuple)
It seems to work great, thank you!
BTW, I haven't followed the entire discussion around constructor_of
, but wouldn't it make sense to rewrite Setfield.jl around setproperties
, with a fall-back to the constructor when it's not implemented? Relying on the constructor never felt quite right to me.
I would say that Setfield.jl
is already designed around setproperties
. The default implementation just uses constructor_of
. Try
Setfield.setproperties(MyType, patch) = ...
Setfield.constructor_of(::Type{<:MyType}) = error()
And Setfield.jl
should work fine with MyType
.
I'm interested in something like
Can I support it? I get an error from
assert_hasfields
because, of course,property
is not a field ofobject
. I'd like to be able to implementsetproperty(::Object, value, sym)
, similar toBase.setindex
, which would return a new object with that property modified. Is that possible?