Mix DerivedOptics.Of[S] into any object to get the optics of S when S is not the class of that object's companion: a generic instantiation such as Box[Int], a type alias, or a type whose companion you cannot change. It works like DerivedOptics, with S given explicitly. optics needs an implicit Schema[S] where it is called, so a schema defined in the object has to be imported there.
Mix DerivedOptics.Of[S] into any object to get the optics of S when S is not the class of that object's companion: a generic instantiation such as Box[Int], a type alias, or a type whose companion you cannot change. It works like DerivedOptics, with S given explicitly. optics needs an implicit Schema[S] where it is called, so a schema defined in the object has to be imported there.
// scala-3-only
case class Box[A](value: A)
object BoxInt extends DerivedOptics.Of[Box[Int]] {
implicit val schema: Schema[Box[Int]] = Schema.derived
}
import BoxInt.schema
val value: Lens[Box[Int], Int] = BoxInt.optics.value