Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bounds to CoproductInstances methods #41

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions modules/deriving/src/main/scala/shapeless3/deriving/kinds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ object K0 {
inst.asInstanceOf

extension [F[_], T](inst: CoproductInstances[F, T])
inline def mapK[G[_]](f: [t] => F[t] => G[t]): CoproductInstances[G, T] =
inline def mapK[G[_]](f: [t <: T] => F[t] => G[t]): CoproductInstances[G, T] =
inst.erasedMapK(f.asInstanceOf).asInstanceOf
inline def inject[R](p: Int)(f: [t <: T] => F[t] => R): R =
inst.erasedInject(p)(f.asInstanceOf).asInstanceOf
@deprecated("use inject", "3.0.2")
inline def project[Acc](p: Int)(i: Acc)(f: [t] => (Acc, F[t]) => (Acc, Option[t])): (Acc, Option[T]) =
inst.erasedProject(p)(i)(f.asInstanceOf).asInstanceOf
inline def fold[R](x: T)(f: [t] => (F[t], t) => R): R =
inline def fold[R](x: T)(f: [t <: T] => (F[t], t) => R): R =
inst.erasedFold(x)(f.asInstanceOf).asInstanceOf
inline def fold2[R](x: T, y: T)(a: => R)(f: [t] => (F[t], t, t) => R): R =
inline def fold2[R](x: T, y: T)(a: => R)(f: [t <: T] => (F[t], t, t) => R): R =
inst.erasedFold2(x, y)(a.asInstanceOf)(f.asInstanceOf).asInstanceOf
inline def fold2[R](x: T, y: T)(g: (Int, Int) => R)(f: [t] => (F[t], t, t) => R): R =
inline def fold2[R](x: T, y: T)(g: (Int, Int) => R)(f: [t <: T] => (F[t], t, t) => R): R =
inst.erasedFold2f(x, y)(g.asInstanceOf)(f.asInstanceOf).asInstanceOf
inline def widen[G[t] >: F[t]]: CoproductInstances[G, T] =
inst.asInstanceOf
Expand Down Expand Up @@ -236,13 +236,13 @@ object K1 {
inst.asInstanceOf

extension [F[_[_]], T[_]](inst: CoproductInstances[F, T])
inline def mapK[G[_[_]]](f: [t[_]] => F[t] => G[t]): CoproductInstances[G, T] =
inline def mapK[G[_[_]]](f: [t[x] <: T[x]] => F[t] => G[t]): CoproductInstances[G, T] =
inst.erasedMapK(f.asInstanceOf).asInstanceOf
inline def fold[A, R](x: T[A])(f: [t[_]] => (F[t], t[A]) => R): R =
inline def fold[A, R](x: T[A])(f: [t[x] <: T[x]] => (F[t], t[A]) => R): R =
inst.erasedFold(x)(f.asInstanceOf).asInstanceOf
inline def fold2[A, B, R](x: T[A], y: T[B])(a: => R)(f: [t[_]] => (F[t], t[A], t[B]) => R): R =
inline def fold2[A, B, R](x: T[A], y: T[B])(a: => R)(f: [t[x] <: T[x]] => (F[t], t[A], t[B]) => R): R =
inst.erasedFold2(x, y)(a.asInstanceOf)(f.asInstanceOf).asInstanceOf
inline def fold2[A, B, R](x: T[A], y: T[B])(g: (Int, Int) => R)(f: [t[_]] => (F[t], t[A], t[B]) => R): R =
inline def fold2[A, B, R](x: T[A], y: T[B])(g: (Int, Int) => R)(f: [t[x] <: T[x]] => (F[t], t[A], t[B]) => R): R =
inst.erasedFold2f(x, y)(g.asInstanceOf)(f.asInstanceOf).asInstanceOf
inline def widen[G[t[_]] >: F[t]]: CoproductInstances[G, T] =
inst.asInstanceOf
Expand Down Expand Up @@ -347,13 +347,13 @@ object K11 {
inst.asInstanceOf

extension [F[_[_[_]]], T[_[_]]](inst: CoproductInstances[F, T])
inline def mapK[G[_[_[_]]]](f: [t[_[_]]] => F[t] => G[t]): CoproductInstances[G, T] =
inline def mapK[G[_[_[_]]]](f: [t[x[_]] <: T[x]] => F[t] => G[t]): CoproductInstances[G, T] =
inst.erasedMapK(f.asInstanceOf).asInstanceOf
inline def fold[A[_], R](x: T[A])(f: [t[_[_]]] => (F[t], t[A]) => R): R =
inline def fold[A[_], R](x: T[A])(f: [t[x[_]] <: T[x]] => (F[t], t[A]) => R): R =
inst.erasedFold(x)(f.asInstanceOf).asInstanceOf
inline def fold2[A[_], B[_], R](x: T[A], y: T[B])(a: => R)(f: [t[_[_]]] => (F[t], t[A], t[B]) => R): R =
inline def fold2[A[_], B[_], R](x: T[A], y: T[B])(a: => R)(f: [t[x[_]] <: T[x]] => (F[t], t[A], t[B]) => R): R =
inst.erasedFold2(x, y)(a.asInstanceOf)(f.asInstanceOf).asInstanceOf
inline def fold2[A[_], B[_], R](x: T[A], y: T[B])(g: (Int, Int) => R)(f: [t[_[_]]] => (F[t], t[A], t[B]) => R): R =
inline def fold2[A[_], B[_], R](x: T[A], y: T[B])(g: (Int, Int) => R)(f: [t[x[_]] <: T[x]] => (F[t], t[A], t[B]) => R): R =
inst.erasedFold2f(x, y)(g.asInstanceOf)(f.asInstanceOf).asInstanceOf
inline def widen[G[t[_[_]]] >: F[t]]: CoproductInstances[G, T] =
inst.asInstanceOf
Expand Down Expand Up @@ -457,13 +457,13 @@ object K2 {
inst.asInstanceOf

extension [F[_[_, _]], T[_, _]](inst: CoproductInstances[F, T])
inline def mapK[G[_[_, _]]](f: [t[_, _]] => F[t] => G[t]): CoproductInstances[G, T] =
inline def mapK[G[_[_, _]]](f: [t[x, y] <: T[x, y]] => F[t] => G[t]): CoproductInstances[G, T] =
inst.erasedMapK(f.asInstanceOf).asInstanceOf
inline def fold[A, B, R](x: T[A, B])(f: [t[_, _]] => (F[t], t[A, B]) => R): R =
inline def fold[A, B, R](x: T[A, B])(f: [t[x, y] <: T[x, y]] => (F[t], t[A, B]) => R): R =
inst.erasedFold(x)(f.asInstanceOf).asInstanceOf
inline def fold2[A, B, C, D, R](x: T[A, B], y: T[C, D])(a: => R)(f: [t[_, _]] => (F[t], t[A, B], t[C, D]) => R): R =
inline def fold2[A, B, C, D, R](x: T[A, B], y: T[C, D])(a: => R)(f: [t[x, y] <: T[x, y]] => (F[t], t[A, B], t[C, D]) => R): R =
inst.erasedFold2(x, y)(a.asInstanceOf)(f.asInstanceOf).asInstanceOf
inline def fold2[A, B, C, D, R](x: T[A, B], y: T[C, D])(g: (Int, Int) => R)(f: [t[_, _]] => (F[t], t[A, B], t[C, D]) => R): R =
inline def fold2[A, B, C, D, R](x: T[A, B], y: T[C, D])(g: (Int, Int) => R)(f: [t[x, y] <: T[x, y]] => (F[t], t[A, B], t[C, D]) => R): R =
inst.erasedFold2f(x, y)(g.asInstanceOf)(f.asInstanceOf).asInstanceOf
inline def widen[G[t[_, _]] >: F[t]]: CoproductInstances[G, T] =
inst.asInstanceOf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class InstancesTests {

val expected = "f 326"
val actual = otherInst.fold[String](f) {
[t] => (f: AnotherTypeClass[t], t: t) => "f " + f.method(t)
[t <: Few[Int]] => (f: AnotherTypeClass[t], t: t) => "f " + f.method(t)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this was necessary - the poly function without a bound should be a subtype

}

assert(actual == expected)
Expand Down