-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d864d9
commit dd422a3
Showing
8 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
21 changes: 21 additions & 0 deletions
21
core/src/main/scala-3.0.0-RC3/cats/derived/semigroupk.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
11 changes: 11 additions & 0 deletions
11
core/src/test/scala-3.0.0-RC3/cats/derived/EmptyKTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/test/scala-3.0.0-RC3/cats/derived/MonoidKTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/test/scala-3.0.0-RC3/cats/derived/SemigroupKTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |