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

Field syntax for optics #1125

Closed
wants to merge 9 commits into from
Closed

Field syntax for optics #1125

wants to merge 9 commits into from

Conversation

julien-truffaut
Copy link
Member

Add a field(lambda) on all Optics such that:

case class User(name: String, address: Address)
case class Address(streeetNumber: Int, postcode: String)

Focus[User]()
  .field(_.address)
  .field(_.streetNumber) == Focus[User](_.address.streetNumber)

It is a bit redundant but this method is meant for updating existing optics:

val user: Lens[State, User] = ... // suppose we have it defined

user.field(_.name) == user.andThen(Focus[User](_.name))

@julien-truffaut julien-truffaut marked this pull request as ready for review March 25, 2021 21:36
case t => c.abort(c.enclosingPosition, s"Invalid prefix tree ${show(t)}")
}

lambda match {
Copy link
Member Author

Choose a reason for hiding this comment

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

This duplicate code from GenLens macro, I couldn't find out how to pass a Boolean flag ...

I don't think it matters too much since it is for Scala 2 and we don't plan to touch macro further in this version of Scala.

@julien-truffaut
Copy link
Member Author

need more discussion, closing for now

@julien-truffaut julien-truffaut mentioned this pull request Jul 27, 2021
@xuwei-k xuwei-k deleted the fields-syntax branch January 9, 2022 10:28
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.

1 participant