From ef445f789db526b8b256d278b67a0434dde053b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0pan=C4=9Bl?= Date: Tue, 23 Jan 2024 16:15:59 +0100 Subject: [PATCH 1/2] Test: demonstrate #210 --- .../com/softwaremill/quicklens/ModifyMapAtTest.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/quicklens/src/test/scala/com/softwaremill/quicklens/ModifyMapAtTest.scala b/quicklens/src/test/scala/com/softwaremill/quicklens/ModifyMapAtTest.scala index ab3631d..45d7653 100644 --- a/quicklens/src/test/scala/com/softwaremill/quicklens/ModifyMapAtTest.scala +++ b/quicklens/src/test/scala/com/softwaremill/quicklens/ModifyMapAtTest.scala @@ -57,4 +57,12 @@ class ModifyMapAtTest extends AnyFlatSpec with Matchers { modify(m1)(_.at("K0").a5.name).using(duplicate) } } + + it should "modify a map using at with a derived class" in { + class C + object D extends C + val m = Map[C, String](D -> "") + val expected = Map(D -> "x") + modify(m)(_.at(D)).setTo("x") should be(expected) + } } From a6f0a5c149c613b94ef3cdcbcda5956b8a8deaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0pan=C4=9Bl?= Date: Tue, 23 Jan 2024 16:25:30 +0100 Subject: [PATCH 2/2] Fix: use contravariance to allow derived index type --- .../src/main/scala-3/com/softwaremill/quicklens/package.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quicklens/src/main/scala-3/com/softwaremill/quicklens/package.scala b/quicklens/src/main/scala-3/com/softwaremill/quicklens/package.scala index 54d5b20..a5c1f9f 100644 --- a/quicklens/src/main/scala-3/com/softwaremill/quicklens/package.scala +++ b/quicklens/src/main/scala-3/com/softwaremill/quicklens/package.scala @@ -161,7 +161,7 @@ package object quicklens { } } - trait QuicklensIndexedFunctor[F[_], I] { + trait QuicklensIndexedFunctor[F[_], -I] { def at[A](fa: F[A], f: A => A, idx: I): F[A] def atOrElse[A](fa: F[A], f: A => A, idx: I, default: => A): F[A] def index[A](fa: F[A], f: A => A, idx: I): F[A]