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

API for internally calculated fields #57

Open
tpapp opened this issue May 10, 2022 · 3 comments
Open

API for internally calculated fields #57

tpapp opened this issue May 10, 2022 · 3 comments

Comments

@tpapp
Copy link

tpapp commented May 10, 2022

I read the docs but it is still not clear how one should define the relevant interface for types that have internally calculated fields. Eg

struct Foo
    a
    b
    c
    Foo(a, b) = new(a, b, hypot(a, b))
end

I want the user to be able to modify (= create a new immutable with) a and b, and pretend that c does not even exist.

@jw3126
Copy link
Member

jw3126 commented May 10, 2022

I agree this is a pain point. What I generally recommend is using setproperties/getproperties for public access and constructorof for private access. See also #54 (comment)

@tpapp
Copy link
Author

tpapp commented May 10, 2022

Sorry if I am missing the obvious, but could you please provide a suggestion to deal with the above struct so that eg
Accessors.@optic _.a etc works to modify a?

@jw3126
Copy link
Member

jw3126 commented May 10, 2022

Did you try to overload ConstructionBase.setproperties?

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