-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
add as extension method to optics in Scala 2 and 3 #1110
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes should be made to Focus too:
- The type signature of the
as
keyword should be changed to be consistent with[From, To <: From]
, which is possible now in RC1 - The implementation of the
AsGenerator
inFocus
should delegate to this external operator functionality, instead of using its own implementation.
implicit def toMacroFoldOps[From, To](optic: Fold[From, To]): MacroFoldOps[From, To] = new MacroFoldOps(optic) | ||
} | ||
|
||
class MacroPrismOps[From, To](private val optic: Prism[From, To]) extends AnyVal { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need an extension per optic type, when have a class hierarchy now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's for narrowing the output type lens.as
is an Optional
but getter.as
is a Fold
. There might be another way to do it with transparent, I am not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, you will note that there is not an extension per Optic type, for example, there is not one Getter
, Iso
, or Lens
as we don't need them to get a more precise return type.
@kenbot I tried to change the definition of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge away, I'll send the Focus changes in a new PR
For Scala 2, I added extension methods in the macro module which basically do
optic.andThen(GenPrism[To, CastTo])
.For Scala 3, I added the same extension methods but in the core module. I could have implemented it by forwarding it to
Focus(_.as[CastTo])
but I am worried about the documentation.I mean for
Focus
it makes sense to usetransparent
because the return type may vary but here we know it before hand. Maybe one of you know a way to do it? Admittedly, I am just copy/pasting and tweaking code but I have no good understanding of the macro APIs.TODO in another PR, do the same for
ApplyOptics
.