相关疑难解决方法(0)

尝试使用Shapeless递归地将case类转换为异类列表的奇怪行为

我昨晚熬夜试图弄清楚这个无形的问题,如果我不把它从胸前拿走,我担心它会吃掉我的晚上,所以这里就是这样.

在这个最小化版本中,我只是定义了一个类型类,它将递归转换为异构列表:

import shapeless._

trait DeepHLister[R <: HList] extends DepFn1[R] { type Out <: HList }

trait LowPriorityDeepHLister {
  type Aux[R <: HList, Out0 <: HList] = DeepHLister[R] { type Out = Out0 }

  implicit def headNotCaseClassDeepHLister[H, T <: HList](implicit
    dht: DeepHLister[T]
  ): Aux[H :: T, H :: dht.Out] = new DeepHLister[H :: T] {
    type Out = H :: dht.Out
    def apply(r: H :: T) = r.head :: dht(r.tail)
  }
}

object DeepHLister extends LowPriorityDeepHLister {
  implicit …
Run Code Online (Sandbox Code Playgroud)

scala shapeless scala-macros

21
推荐指数
2
解决办法
1208
查看次数

标签 统计

scala ×1

scala-macros ×1

shapeless ×1