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

Recommended replacement for @Lenses #1181

Open
Lermex opened this issue Jul 21, 2021 · 4 comments
Open

Recommended replacement for @Lenses #1181

Lermex opened this issue Jul 21, 2021 · 4 comments

Comments

@Lermex
Copy link

Lermex commented Jul 21, 2021

Am I right to assume that using Focus at all use sites instead of lenses pre-generated with the @Lenses annotation is gonna affect compilation times in the same way e.g. using circe.auto instead of circe.semiauto does? If so, what's the recommended approach here?

Should I replace @Lenses with something like val lens = GenLens[MyClass] in the MyClass companion object?

Is there a plan to support the derives clause in Monocle?

@yilinwei
Copy link
Collaborator

Rather than compile-times (it's fairly fast), you'll get code blow up since it generates an in-line method each call-site; YMMV as to whether you care or not.

You can use the Focus object or GenLens to share the optic. Your snippet is probably what I would do.

I don't understand what derives support would entail. Could you please elaborate?

@Lermex
Copy link
Author

Lermex commented Jul 26, 2021

Presumably, you would be able to write

case class MyClass (
  fieldOne: String,
  fieldTwo: Int
) derives Lenses

and then either do MyClass.fieldOne or MyClass.lens.fieldOne to access the lens for a particular field

@japgolly
Copy link
Contributor

japgolly commented Aug 2, 2021

@Lermex I don't think it works that way. IIUC derives Lenses would result in val lenses = Lenses.derived[MyClass] to be added to object MyClass. I don't think it has the capability to add multiple named fields to object MyClass unfortunately. (Would be awesome though!)

@yilinwei
Copy link
Collaborator

FYI, scala/scala3#16454

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

No branches or pull requests

3 participants