diff --git a/core/src/main/scala/shapeless/ops/hlists.scala b/core/src/main/scala/shapeless/ops/hlists.scala index 6b3ff677e..a96886cae 100644 --- a/core/src/main/scala/shapeless/ops/hlists.scala +++ b/core/src/main/scala/shapeless/ops/hlists.scala @@ -3074,26 +3074,26 @@ object hlist { * * @author Michael Zuber */ - sealed trait ToHList[-T] { + sealed trait ProductToHList[-T] extends Serializable { type Out <: HList def apply(t: T): Out } - object ToHList { - def apply[P](implicit ev: ToHList[P]): ToHList[P] = ev + object ProductToHList { + def apply[P](implicit ev: ProductToHList[P]): ProductToHList[P] = ev - type Aux[P, HL <: HList] = ToHList[P] { type Out = HL } + type Aux[P, HL <: HList] = ProductToHList[P] { type Out = HL } - implicit def hconsToHList[H, TH, TT, HL <: HList](implicit - ev: ToHList.Aux[Product2[TH, TT], HL] - ): ToHList.Aux[Product2[H, Product2[TH, TT]], H :: HL] = new ToHList[Product2[H, Product2[TH, TT]]] { + implicit def pairToHCons[H, T, HL <: HList]( + implicit ev: ProductToHList.Aux[T, HL] + ): ProductToHList.Aux[Product2[H, T], H :: HL] = new ProductToHList[Product2[H, T]] { type Out = H :: HL - def apply(p: Product2[H, Product2[TH, TT]]): Out = p._1 :: ev(p._2) + def apply(p: Product2[H, T]): Out = p._1 :: ev(p._2) } - implicit def hnilToHList[H]: ToHList.Aux[Product2[H, Unit], H :: HNil] = new ToHList[Product2[H, Unit]] { - type Out = H :: HNil - def apply(p: Product2[H, Unit]): Out = p._1 :: HNil + implicit val unitToHNil: ProductToHList.Aux[Unit, HNil] = new ProductToHList[Unit] { + type Out = HNil + def apply(p: Unit): Out = HNil } } @@ -3102,23 +3102,23 @@ object hlist { * * @author Michael Zuber */ - sealed trait HListToProduct[HL <: HList] extends DepFn1[HL] { type Out <: Product } + sealed trait HListToProduct[HL <: HList] extends DepFn1[HL] with Serializable object HListToProduct { def apply[HL <: HList](implicit ev: HListToProduct[HL]): HListToProduct[HL] = ev - type Aux[HL <: HList, P <: Product] = HListToProduct[HL] { type Out = P } + type Aux[HL <: HList, P] = HListToProduct[HL] { type Out = P } - implicit def hnilToProduct[H]: HListToProduct.Aux[H :: HNil, Product2[H, Unit]] = new HListToProduct[H :: HNil] { - type Out = Product2[H, Unit] - def apply(hl: H :: HNil): Out = (hl.head, ()) + implicit val hnilToUnit: HListToProduct.Aux[HNil, Unit] = new HListToProduct[HNil] { + type Out = Unit + def apply(hl: HNil): Out = () } - implicit def hconsHListToProduct[H, T <: HList, TP <: Product](implicit - ev: HListToProduct.Aux[T, TP] - ): HListToProduct.Aux[H :: T, Product2[H, TP]] = new HListToProduct[H :: T] { - type Out = Product2[H, TP] - def apply(hl: H :: T) = (hl.head, ev(hl.tail)) + implicit def hconsToPair[H, T <: HList, TP]( + implicit ev: HListToProduct.Aux[T, TP] + ): HListToProduct.Aux[H :: T, (H, TP)] = new HListToProduct[H :: T] { + type Out = (H, TP) + def apply(hl: H :: T): Out = (hl.head, ev(hl.tail)) } } } diff --git a/core/src/main/scala/shapeless/syntax/hlists.scala b/core/src/main/scala/shapeless/syntax/hlists.scala index 7c08acd1d..1c025aad2 100644 --- a/core/src/main/scala/shapeless/syntax/hlists.scala +++ b/core/src/main/scala/shapeless/syntax/hlists.scala @@ -748,5 +748,5 @@ final class HListOps[L <: HList](l : L) extends Serializable { /** * Converts this `HList` into a nested pair */ - def nestedProduct(implicit hListToProduct: HListToProduct[L]): hListToProduct.Out = hListToProduct(l) + def toProduct(implicit hListToProduct: HListToProduct[L]): hListToProduct.Out = hListToProduct(l) } diff --git a/core/src/main/scala/shapeless/syntax/std/tuples.scala b/core/src/main/scala/shapeless/syntax/std/tuples.scala index 4d701c007..2bde7db13 100644 --- a/core/src/main/scala/shapeless/syntax/std/tuples.scala +++ b/core/src/main/scala/shapeless/syntax/std/tuples.scala @@ -18,6 +18,8 @@ package shapeless package syntax package std +import shapeless.ops.hlist.ProductToHList + trait LowPriorityTuple { implicit def productTupleOps[P <: Product](p: P): TupleOps[P] = new TupleOps(p) } @@ -524,5 +526,5 @@ final class TupleOps[T](t: T) extends Serializable { /** * Converts this nested `Product` into an `HList` */ - def toHList(implicit toHList: ops.hlist.ToHList[T]): toHList.Out = toHList(t) + def toHList(implicit productToHList: ProductToHList[T]): productToHList.Out = productToHList(t) } \ No newline at end of file diff --git a/core/src/test/scala/shapeless/hlist.scala b/core/src/test/scala/shapeless/hlist.scala index b61cc8243..2b615cea8 100644 --- a/core/src/test/scala/shapeless/hlist.scala +++ b/core/src/test/scala/shapeless/hlist.scala @@ -3490,9 +3490,11 @@ class HListTests { val p = (2, ("abc", (true, (3.0, ())))) import syntax.std.tuple._ - assertEquals(isbd.nestedProduct, p) + assertEquals(isbd.toProduct, p) assertEquals(p.toHList, isbd) - assertEquals(isbd.nestedProduct.toHList, isbd) - assertEquals(p.toHList.nestedProduct, p) + assertEquals(isbd.toProduct.toHList, isbd) + assertEquals(p.toHList.toProduct, p) + assertEquals((), (HNil: HNil).toProduct) + assertEquals(HNil, ().toHList) } }