Skip to content

Commit

Permalink
Avoid existential types in implicits
Browse files Browse the repository at this point in the history
Also ensure `HListShape` has the correct `ShapeLevel`.

Fixes milessabin/shapeless#619
  • Loading branch information
joroKr21 committed Jan 23, 2018
1 parent ecc0d5d commit 7b484cf
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/main/scala/slickless/HListShape.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,32 @@ final class HListShape[L <: ShapeLevel, M <: HList, U <: HList : ClassTag, P <:

trait HListShapeImplicits {
implicit def hnilShape[L <: ShapeLevel]: HListShape[L, HNil, HNil, HNil] =
new HListShape[L, HNil, HNil, HNil](Nil)
new HListShape(Nil)

implicit def hconsShape[L <: ShapeLevel, M1, M2 <: HList, U1, U2 <: HList, P1, P2 <: HList]
(implicit s1: Shape[_ <: ShapeLevel, M1, U1, P1], s2: HListShape[_ <: ShapeLevel, M2, U2, P2]):
HListShape[L, M1 :: M2, U1 :: U2, P1 :: P2] =
new HListShape[L, M1 :: M2, U1 :: U2, P1 :: P2](s1 +: s2.shapes)
implicit def hconsShape[
L <: ShapeLevel, L1 <: L, L2 <: L,
M1, M2 <: HList,
U1, U2 <: HList,
P1, P2 <: HList
](implicit
s1: Shape[L1, M1, U1, P1],
s2: HListShape[L2, M2, U2, P2]
): HListShape[L, M1 :: M2, U1 :: U2, P1 :: P2] =
new HListShape(s1 +: s2.shapes)

implicit class HListShapeOps[T <: HList](hlist: T) {
def mappedWith[R: ClassTag, U <: HList](gen: Generic.Aux[R, U])
(implicit shape: Shape[_ <: FlatShapeLevel, T, U, _]) =
new MappedProjection[R, U](
shape.toNode(hlist),
MappedScalaType.Mapper(
(gen.to _).asInstanceOf[Any => Any],
(gen.from _).asInstanceOf[Any => Any],
None
),
implicitly[ClassTag[R]]
)
def mappedWith[
R: ClassTag, U <: HList, L <: FlatShapeLevel, P
](gen: Generic.Aux[R, U])(
implicit shape: Shape[L, T, U, P]
) = new MappedProjection[R, U](
shape.toNode(hlist),
MappedScalaType.Mapper(
(gen.to _).asInstanceOf[Any => Any],
(gen.from _).asInstanceOf[Any => Any],
None
),
implicitly[ClassTag[R]]
)
}
}

0 comments on commit 7b484cf

Please sign in to comment.