Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Brings as into line with the other operators wrt Focus #1112

Merged
merged 1 commit into from
Mar 6, 2021

Conversation

kenbot
Copy link
Collaborator

@kenbot kenbot commented Mar 6, 2021

  • Thanks to Scala 3 RC1, adds a From parameter to the Focus as keyword, constrained by a type bounds. This is now the same signature as the external as operator:
extension [From] (from: From)
      def as[CastTo <: From]: CastTo
  • Adds a case to the FocusKeyword pattern matcher to correctly interpret an extension method with both inferred and direct type parameter lists.
  • Renamed GenPrism to AsPrism. It is no longer analogous to the deprecated GenXXX features, and should not forward to Focus. It is an implementation detail for the new and supported as operator.
  • Changed the AsGenerator implementation to directly use AsPrism, rather than have its own operation. This is now the same as the other features, which all generate code that delegates to the external operator. We are using the implementation class AsPrism rather than the direct as operator because the external one is only accessible as an optic extension method. The way Focus works, each optic is generated on its own and composed together later, so we can't call an extension method on the last thing generated.
  • Removed the CastTo <: To constraint in the AsPrism implementation, because proving the relationship was hard inside the Focus macro. It is sufficient to enforce the constraint in the public interface.
  • Added some tests to confirm that the Focus and external as operators commute with respect to each other, just like the other operators

@kenbot kenbot requested a review from julien-truffaut March 6, 2021 13:59
case ('[f], '[t]) => '{
Prism[f, t]((from: f) => if (from.isInstanceOf[t]) Some(from.asInstanceOf[t]) else None)
((to: t) => to.asInstanceOf[f]) }.asTerm
case ('[f], '[t]) => '{ AsPrism[f, t] }.asTerm
Copy link
Member

Choose a reason for hiding this comment

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

Nice

Copy link
Member

@julien-truffaut julien-truffaut left a comment

Choose a reason for hiding this comment

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

Great!

@julien-truffaut julien-truffaut merged commit be8ab26 into optics-dev:master Mar 6, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants