Replies: 3 comments 1 reply
-
Thanks for the proposal @serras 🙏 Looks good to me! We should focus on the practical, and what people are using. I like your proposal for
🥳, I think we can also ditch the extension for We should also fix this issue while tackling this, #2668. |
Beta Was this translation helpful? Give feedback.
-
I'm working on it at #2873 |
Beta Was this translation helpful? Give feedback.
-
In #2851 I proposed to align the optics hierarchy in Arrow 2.0 to those in other communities. In particular, get rid of some confusion like
Traversal
being essentially aSetter
andEvery
being what other callTraversal
. I think this is a must have, otherwise Arrow stays the weird one in the crowd.However, I think there's room for further simplification, based on the way people use Optics. More concretely, I propose to reduce the API to the four types marked in the picture above. The documentation is then simplified by simply talking about "focusing", and having no distinction between "set" and "get":
Traversal
focuses in any amount of elements, perfect for working with collections,Optional
is 0 or 1, perfect for focusing on one choice out of asealed
hierarchy,Lens
in exactly 1, perfect for focusing on fields,Prism
is anOptional
which can be "reversed", which is "the other side" of asealed
hierarchy.In addition, I propose to change the derivation of optics for nullable fields. Right now for
amount: Int?
we generate anOptional
, but I think people find it surprising that it only "sets" when the field was already not null. Instead of this, I propose to generate aLens
, and introduce a new combinator,so "going under a
null
" is explicit in the same way that you need to callevery
to "go under a list".An additional advantage is that this streamlined hierarchy allows us to reduce the binary size, a common complaint when using Optics. The key problem is that before we generated extension fields for every possible combination,
but now we only have 4, so we've effectively halved the size.
I'm happy to work on this, both on the library side and the compiler plug-in side.
Beta Was this translation helpful? Give feedback.
All reactions