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

[Optics] Optional getter #2611

Merged
merged 4 commits into from Feb 9, 2022
Merged

[Optics] Optional getter #2611

merged 4 commits into from Feb 9, 2022

Conversation

serras
Copy link
Member

@serras serras commented Dec 24, 2021

PR #2588 has shown that there's a missing element in the optics hierarchy: folds focus on 0..N, getters focus on exactly 1, so we are missing something which focuses on 0..1. This is OptionalGetter, the "get" part of Optional and Prism. In other libraries this is called an AffineFold. However, I find that name very obscure. Feel free to suggest changes.

In particular, the operation of filtering is one such OptionalGetter. The implementation is a copy of the one provided by @lenguyenthanh in #2588 (thank you for that!).

A technical note: you may notice that it is not the case that Getter<S, A> extends OptionalGetter<S, A>. This is because the right way to describe the relation is that Getter<S, A> is a POptionalGetter<S, T, A> for any choice of T (since it never returns it). Alas, Kotlin does not allow us to declare that relationship. One way to handle this would be to use something like OptionalGetter<S, Nothing, A>, but unfortunately the T must be invariant :(

Copy link
Member

@nomisRev nomisRev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, a small mistake in the title of the markdown doc.

arrow-site/docs/docs/optional_getter/README.md Outdated Show resolved Hide resolved
@nomisRev nomisRev requested a review from a team February 8, 2022 13:56
Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
@serras serras merged commit 5056131 into main Feb 9, 2022
@serras serras deleted the optics-optional-getter branch February 9, 2022 13:03
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.

None yet

3 participants