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

Remove code duplication of summonFirst0 #35

Merged
merged 1 commit into from
Sep 26, 2021
Merged
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
50 changes: 21 additions & 29 deletions modules/deriving/src/main/scala/shapeless3/deriving/kinds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ object K0 {
case _ => EmptyTuple
}

inline def summonFirst[F[_], T, U]: F[U] = summonFirst0[LiftP[F, T]].asInstanceOf[F[U]]

transparent inline def summonFirst0[T]: Any = inline erasedValue[T] match {
case _: (a *: b) => summonFrom {
case aa: `a` => aa
case _ => summonFirst0[b]
}
}
inline def summonFirst[F[_], T, U]: F[U] =
summonFirst0[LiftP[F, T]].asInstanceOf[F[U]]

transparent inline def summonFirst0[T]: Any =
inline erasedValue[T] match
case _: (a *: b) => summonFrom {
case instance: `a` => instance
case _ => summonFirst0[b]
}

extension [T](gen: ProductGeneric[T])
inline def toRepr(o: T): gen.MirroredElemTypes = Tuple.fromProduct(o.asInstanceOf).asInstanceOf[gen.MirroredElemTypes]
Expand Down Expand Up @@ -184,14 +185,11 @@ object K1 {
case _ => EmptyTuple
}

inline def summonFirst[F[_[_]], T[_], U[_]]: F[U] = summonFirst0[LiftP[F, T]].asInstanceOf[F[U]]
inline def summonFirst[F[_[_]], T[_], U[_]]: F[U] =
K0.summonFirst0[LiftP[F, T]].asInstanceOf[F[U]]

transparent inline def summonFirst0[T]: Any = inline erasedValue[T] match {
case _: (a *: b) => summonFrom {
case aa: `a` => aa
case _ => summonFirst0[b]
}
}
transparent inline def summonFirst0[T]: Any =
K0.summonFirst0[T]

extension [T[_], A] (gen: ProductGeneric[T])
inline def toRepr(o: T[A]): gen.MirroredElemTypes[A] = Tuple.fromProduct(o.asInstanceOf).asInstanceOf[gen.MirroredElemTypes[A]]
Expand Down Expand Up @@ -298,14 +296,11 @@ object K11 {
case _ => EmptyTuple
}

inline def summonFirst[F[_[_[_]]], T[_[_]], U[_[_]]]: F[U] = summonFirst0[LiftP[F, T]].asInstanceOf[F[U]]
inline def summonFirst[F[_[_[_]]], T[_[_]], U[_[_]]]: F[U] =
K0.summonFirst0[LiftP[F, T]].asInstanceOf[F[U]]

transparent inline def summonFirst0[T]: Any = inline erasedValue[T] match {
case _: (a *: b) => summonFrom {
case aa: `a` => aa
case _ => summonFirst0[b]
}
}
transparent inline def summonFirst0[T]: Any =
K0.summonFirst0[T]

extension [T[_[_]], A[_]](gen: ProductGeneric[T])
inline def toRepr(o: T[A]): gen.MirroredElemTypes[A] = Tuple.fromProduct(o.asInstanceOf).asInstanceOf[gen.MirroredElemTypes[A]]
Expand Down Expand Up @@ -413,14 +408,11 @@ object K2 {
case _ => EmptyTuple
}

inline def summonFirst[F[_[_, _]], T[_, _], U[_, _]]: F[U] = summonFirst0[LiftP[F, T]].asInstanceOf[F[U]]
inline def summonFirst[F[_[_, _]], T[_, _], U[_, _]]: F[U] =
K0.summonFirst0[LiftP[F, T]].asInstanceOf[F[U]]

transparent inline def summonFirst0[T]: Any = inline erasedValue[T] match {
case _: (a *: b) => summonFrom {
case aa: `a` => aa
case _ => summonFirst0[b]
}
}
transparent inline def summonFirst0[T]: Any =
K0.summonFirst0[T]

extension [T[_, _], A, B](gen: ProductGeneric[T]) inline def toRepr(o: T[A, B]): gen.MirroredElemTypes[A, B] = Tuple.fromProduct(o.asInstanceOf).asInstanceOf[gen.MirroredElemTypes[A, B]]
extension [T[_, _], A, B](gen: ProductGeneric[T]) inline def fromRepr(r: gen.MirroredElemTypes[A, B]): T[A, B] = gen.fromProduct(r.asInstanceOf).asInstanceOf[T[A, B]]
Expand Down