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

Adding hasproperty overload for lenses #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bradcarman
Copy link

It's useful to have the hasproperty(obj, lens) function in some cases before calling Setfield.set(obj, lens, val)

@jw3126
Copy link
Owner

jw3126 commented Oct 27, 2022

Thanks for the interesting proposal and PR. I think it would be useful to have a way to find out if a lens is applicable to an object. not just for property lenses.
In general this is difficult to implement though, especially for user defined lenses. That is why we did not do that (yet).

@phipsgabler
Copy link
Collaborator

Indeed this would be nice to have. Such a check is a simplified case of what we call subsumption in Turing/AbstractPPL. It gets complicated quickly... but maybe our implementation can provide some ideas and test cases for Setfield.

@aplavin
Copy link
Contributor

aplavin commented Apr 22, 2024

The functionality is useful, but shouldn't really be a method of hasproperty: you don't do getproperty and setproperty! with optics, right? :)

For Accessors optics, this check is performed by the hasoptic() function in AccessorsExtra.jl.
It can, and probably should, be upstreamed to Acceessors itself at some point – but for the sake of future stability, better to define the proper semantics first. See JuliaObjects/Accessors.jl#92 for some discussion + open questions on semantics.

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

Successfully merging this pull request may close these issues.

4 participants