-
Notifications
You must be signed in to change notification settings - Fork 19
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 to query if something is a lens/optic #50
Comments
This is a tricky design question. It will need multiple iterations before we get it right, but let'stry. Some thoughts:
|
Let's start with the use case: a function can take a lens, or a black box closure that struct Foo
a
b
end with either Of course I would prefer the lens, but there are corner cases when just throwing a closure at it is easier for the user. Regarding your suggestions:
|
I think this use case can best be solved with a function like Requiring all lenses to define |
I think @aplavin makes a good point. We need more use cases to justify adding |
@aplavin: I agree that it can be implemented with that wrapper, but it depends on the context whether one wants to make that part of an interface. The only issue is user convenience. @jw3126: Yes, I understand that it is a breaking change, and there is no need to rush so let's leave this issue open to collect use cases. That said, a lot of Julia APIs have a function to query if something supports that API, eg |
My suggestion was precisely to make it part of the user interface. In simple cases, users pass lenses:
Implementing a Table from scratch is much more involved than a lens, so an extra method definition doesn't noticeably affect it. Meanwhile, a simple lens definition is just:
Defining another method ( If one doesn't care much about corner cases, it should be possible to craft |
It would be very useful to have a function that can determine if an object obeys the lens API. Ideally with traits. Eg something like
(After discussion, I am of course happy to make a PR).
The text was updated successfully, but these errors were encountered: