diff --git a/core/src/main/scala-3.0.0-RC3/cats/derived/all.scala b/core/src/main/scala-3.0.0-RC3/cats/derived/all.scala index 2d7d353e..dc7f2b14 100644 --- a/core/src/main/scala-3.0.0-RC3/cats/derived/all.scala +++ b/core/src/main/scala-3.0.0-RC3/cats/derived/all.scala @@ -4,13 +4,16 @@ object all extends CommutativeMonoidDerivation, CommutativeSemigroupDerivation, EmptyDerivation, + EmptyKDerivation, EqDerivation, FoldableDerivation, FunctorDerivation, HashDerivation, MonoidDerivation, + MonoidKDerivation, OrderDerivation, PartialOrderDerivation, SemigroupDerivation, + SemigroupKDerivation, ShowDerivation, TraverseDerivation diff --git a/core/src/main/scala-3.0.0-RC3/cats/derived/emptyk.scala b/core/src/main/scala-3.0.0-RC3/cats/derived/emptyk.scala new file mode 100644 index 00000000..395cc167 --- /dev/null +++ b/core/src/main/scala-3.0.0-RC3/cats/derived/emptyk.scala @@ -0,0 +1,19 @@ +package cats.derived + +import alleycats.{Empty, EmptyK} +import shapeless3.deriving.K1 + +object emptyk extends EmptyKDerivation + +trait ProductEmptyK[T[x[_]] <: EmptyK[x], F[_]]( + using inst: K1.ProductInstances[T, F] +) extends EmptyK[F]: + def empty[A]: F[A] = inst.construct([t[_]] => (emp: T[t]) => emp.empty[A]) + +trait EmptyKDerivation: + extension (E: EmptyK.type) + inline def derived[F[_]](using gen: K1.ProductGeneric[F]): EmptyK[F] = + new ProductEmptyK[EmptyK, F]{} + + given [X](using X: Empty[X]): EmptyK[Const[X]] with + def empty[A]: Const[X][A] = X.empty diff --git a/core/src/main/scala-3.0.0-RC3/cats/derived/functor.scala b/core/src/main/scala-3.0.0-RC3/cats/derived/functor.scala index 7a31d0e9..5c63b44b 100644 --- a/core/src/main/scala-3.0.0-RC3/cats/derived/functor.scala +++ b/core/src/main/scala-3.0.0-RC3/cats/derived/functor.scala @@ -22,4 +22,4 @@ trait FunctorDerivation: new ProductFunctor[Functor, F]{} given [X]: Functor[Const[X]] with - def map[A, B](fa: Const[X][A])(f: A => B): Const[X][B] = fa + def map[A, B](fa: Const[X][A])(f: A => B): Const[X][B] = fa diff --git a/core/src/main/scala-3.0.0-RC3/cats/derived/monoidk.scala b/core/src/main/scala-3.0.0-RC3/cats/derived/monoidk.scala new file mode 100644 index 00000000..aa1ebc53 --- /dev/null +++ b/core/src/main/scala-3.0.0-RC3/cats/derived/monoidk.scala @@ -0,0 +1,20 @@ +package cats.derived + +import cats.{Monoid, MonoidK} +import shapeless3.deriving.K1 + +object monoidk extends MonoidKDerivation + +trait ProductMonoidK[T[x[_]] <: MonoidK[x], F[_]](using inst: K1.ProductInstances[T, F]) + extends ProductSemigroupK[T, F], MonoidK[F]: + def empty[A]: F[A] = inst.construct([t[_]] => (emp: T[t]) => emp.empty[A]) + +trait MonoidKDerivation: + extension (F: MonoidK.type) + inline def derived[F[_]](using gen: K1.Generic[F]): MonoidK[F] = ??? + + given [X](using X: Monoid[X]): MonoidK[Const[X]] with + def empty[A]: Const[X][A] = X.empty + + def combineK[A](x: Const[X][A], y: Const[X][A]): Const[X][A] = + X.combine(x, y) diff --git a/core/src/main/scala-3.0.0-RC3/cats/derived/semigroupk.scala b/core/src/main/scala-3.0.0-RC3/cats/derived/semigroupk.scala new file mode 100644 index 00000000..82248a7c --- /dev/null +++ b/core/src/main/scala-3.0.0-RC3/cats/derived/semigroupk.scala @@ -0,0 +1,21 @@ +package cats.derived + +import cats.{Semigroup, SemigroupK} +import shapeless3.deriving.K1 + +object semigroupk extends SemigroupKDerivation + +trait ProductSemigroupK[T[x[_]] <: SemigroupK[x], F[_]](using inst: K1.ProductInstances[T, F]) + extends SemigroupK[F]: + def combineK[A](x: F[A], y: F[A]): F[A] = inst.map2[A, A, A](x,y)( + [t[_]] => (smgrpk: T[t], t0: t[A], t1: t[A]) => smgrpk.combineK(t0, t1) + ) + +trait SemigroupKDerivation: + extension (F: SemigroupK.type) + inline def derived[F[_]](using gen: K1.ProductGeneric[F]): SemigroupK[F] = + new ProductSemigroupK[SemigroupK, F]{} + + given [X](using X: Semigroup[X]): SemigroupK[Const[X]] with + def combineK[A](x: Const[X][A], y: Const[X][A]): Const[X][A] = + X.combine(x, y) diff --git a/core/src/test/scala-3.0.0-RC3/cats/derived/EmptyKTests.scala b/core/src/test/scala-3.0.0-RC3/cats/derived/EmptyKTests.scala new file mode 100644 index 00000000..78af4711 --- /dev/null +++ b/core/src/test/scala-3.0.0-RC3/cats/derived/EmptyKTests.scala @@ -0,0 +1,11 @@ +package cats.derived + +import alleycats._ +import alleycats.std.all._ +import cats._ +import cats.derived.all._ +import cats.derived.all.given + +class EmptyKTests { // + case class Foo[A](i: String, l: List[A]) derives EmptyK +} diff --git a/core/src/test/scala-3.0.0-RC3/cats/derived/MonoidKTests.scala b/core/src/test/scala-3.0.0-RC3/cats/derived/MonoidKTests.scala new file mode 100644 index 00000000..efefb4ce --- /dev/null +++ b/core/src/test/scala-3.0.0-RC3/cats/derived/MonoidKTests.scala @@ -0,0 +1,10 @@ +package cats.derived + +import alleycats._ +import cats._ +import cats.derived.all._ +import cats.derived.all.given + +class MonoidKTests { // + case class Foo[A](i: String, l: List[A]) derives MonoidK +} diff --git a/core/src/test/scala-3.0.0-RC3/cats/derived/SemigroupKTests.scala b/core/src/test/scala-3.0.0-RC3/cats/derived/SemigroupKTests.scala new file mode 100644 index 00000000..f5a7f143 --- /dev/null +++ b/core/src/test/scala-3.0.0-RC3/cats/derived/SemigroupKTests.scala @@ -0,0 +1,10 @@ +package cats.derived + +import alleycats._ +import cats._ +import cats.derived.all._ +import cats.derived.all.given + +class SemigroupKTests { // + case class Foo[A](i: String, l: List[A]) derives SemigroupK +}