Accessors.jl icon indicating copy to clipboard operation
Accessors.jl copied to clipboard

String properties not supported

Open aplavin opened this issue 1 year ago • 3 comments

julia> @optic _."abc"
ERROR: TypeError: in Type, in parameter, expected Type, got a value of type String

This is because PropertyLens is defined to hold the property name as a type parameter, and Strings cannot be type params. Not sure what we can do, but maybe someone has ideas on how to fix it?

aplavin avatar Mar 20 '24 14:03 aplavin

We could fix it by storing it as a symbol using StringPropertyLens. Do we want and need that?

jw3126 avatar Mar 20 '24 14:03 jw3126

I noticed this missing in terms of actual underlying functionality, not syntax: that is, I haven't needed @o _."abc" syntax yet, but wanted a way to refer to arbitrary properties. Their "names" in Julia can be symbols or int (these are supported by PropertyLens), but also strings (actually occur in the ecosystem) or arbitrary objects (haven't seen these in practice).

aplavin avatar Mar 20 '24 14:03 aplavin

We could also have

struct DynamicPropertyLens{T}
    propertyname::T
end

jw3126 avatar Mar 20 '24 15:03 jw3126