optics-dev / Monocly

Optics experimentation for Dotty
MIT License
32 stars 5 forks source link

Add `some` feature to Focus (previously `?`) #17

Closed kenbot closed 3 years ago

kenbot commented 3 years ago

Assuming #15 is merged, the ? DSL feature will need to be restored. This should be pretty straightforward; Yilin's working code for this can be adapted in some way, I think.

kenbot commented 3 years ago

@julien-truffaut

Previously in Monocle 2 we added Possible as an at-most-one version of Each. My motivation in suggesting it was the exact same feature in Goggles, where I wanted the ? syntax to operate on things like Either[Err,A] or enums with a canonical success case and a bunch of failures cases, which are both very widespread in Scala code.

I see that Possible is now deprecated without replacement - what is the thinking going forward? That the some/pSome on Option are what we really want and the other cases are not significant enough to purchase their own abstraction?

I'm happy either way, it just affects how I implement this feature.

julien-truffaut commented 3 years ago

Yeah my impression was that we tend to use Option most of the time in data model. Either and other error types are more often used in method return types. But it might just be me who used it this way.

Scala 3 has better type inference of polymorphic optics, so it might be more useful to focus on monorphic and polymorphic Option rather than to support other data types like Either or cats.Xor. Maybe we can do both?

I proposed to deprecate lots of combinators to see if anyone is going to comment. I don't have a strong position on that, if they are useful to people, we can rollback the deprecation.

kenbot commented 3 years ago

Yep, fair. Monocle 3 is the big chance to simplify things and remove the cruft. Easy enough to add back in if people want it.

On Thu, 28 Jan 2021, 8:45 pm Julien Truffaut, notifications@github.com wrote:

Yeah my impression was that we tend to use Option most of the time in data model. Either and other error types are more often used in method return types. But it might just be me who used it this way.

Scala 3 has better type inference of polymorphic optics, so it might be more useful to focus on monorphic and polymorphic Option rather than to support other data types like Either or cats.Xor. Maybe we can do both?

I proposed to deprecate lots of combinators to see if anyone is going to comment. I don't have a strong position on that, if they are useful to people, we can rollback the deprecation.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/optics-dev/Monocly/issues/17#issuecomment-768930766, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACNIY6FPOA44G6QSMRLHVDS4EW2RANCNFSM4WCQ6BPQ .

kenbot commented 3 years ago

Suggested law: Focus[Foo](_.bar.some) == Focus[Foo](_.bar).some

kenbot commented 3 years ago

There's no equivalent of monocle.std.Option.pSome in here yet. What are we supposed to be building off for this feature? @julien-truffaut

julien-truffaut commented 3 years ago

@kenbot It is PPrism.some. I put it in the companion object of Prism/PPrism instead of a dedicated Option object. I can move things around so that it works like Monocle 2, what do you think?

kenbot commented 3 years ago

Oh, cool! No need to do anything, it will be easy to change later if we want.

kenbot commented 3 years ago

Solved in #38