을 추가 할 수있는 HList
위에 래퍼를 만들었습니다. 다음과 같이 정의됩니다HList 변환 출력 유형
case class CC(i: Int, ii: Int)
val cc = CC(100, 1000)
val hl = HListWrapper(cc)
hl.append('iii, 10000)
을하지만 Out
의 유형을 캡처하는 다른 함수 내부의 HListWrapper
를 넣어하려고 할 때, 컴파일러는 해결 수없는 것 :
class HListWrapper[L <: HList](val hl: L) {
def append[V, Out <: HList](k: Witness, v: V)(implicit updater: Updater.Aux[L, FieldType[k.T, V], Out],
lk: LacksKey[L, k.T]): HListWrapper[Out] = {
new HListWrapper(updater(hl, field[k.T](v)))
}
}
object HListWrapper {
def apply[P <: Product, L <: HList](p: P)(implicit gen: LabelledGeneric.Aux[P, L]) =
new HListWrapper(gen.to(p))
}
그것은 다음과 같이 사용 변환의 최종 타입 (타입 불일치 에러 실패)
def cctohlist[Out <: HList]: CC => HListWrapper[Out] = {
m => {
val hl = HListWrapper(m)
hl.append('iii, 10000)
}
}
주된 이유는 cctohlist
방법 GE이다 만들 t 추가 후 HList
의 유형. 이것을 달성 할 수 있습니까?
감사합니다. 'cctolist'를 추가 한 후에'HList'의 타입을 얻는 다른 방법이 있습니까? – jamborta
@jamborta 답변을 업데이트했습니다. –