Monocle icon indicating copy to clipboard operation
Monocle copied to clipboard

Variance for optics type parameters

Open kenbot opened this issue 4 years ago • 1 comments

Add variance to the optics type parameters, eg [-S, +T, +A, -B].

Julien:

It helps with Some(1).focus(_.some).replace(2)

Without variance, I believe you get an error and need to manually upcast Some(1): Option[Int]

This example used to work in Monocly: https://github.com/optics-dev/Monocly/blob/master/src/main/scala/Main.scala#L24-L26

kenbot avatar Feb 11 '21 00:02 kenbot

It is likely we will have some issues with cats typeclasses beeing invariants like Functor or Applicative. We need to use @uncheckedVariance annotations.

julien-truffaut avatar Feb 11 '21 18:02 julien-truffaut