Etam
Etam

Reputation: 4673

Scala Monocle - Cannot find method id in E

The class definition looks like this:

abstract class EntityWithIdHelper[E <: { def id: Int }] {
  def idLens: Lens[E, Int] = GenLens[E](_.id)
  ...

How do you avoid this problem - Cannot find method id in E? Is there any workaround?

Upvotes: 5

Views: 227

Answers (1)

Julien Truffaut
Julien Truffaut

Reputation: 497

You cannot create a Lens for id because a Lens requires a getter and a setter and here you only have a getter.

Also if you want to use GenLens[E], E has to be a case class.

Upvotes: 4

Related Questions