I want to build general solution for field removing from case classes. Using this trick I built this working code:
implicit class SemiGenericIgnoringOps[T](t: T) {
def ignoring[TRepr <: HList,
V,
TargetRepr <: HList,
H <: HList](k: Witness)
(implicit
gen: LabelledGeneric.Aux[T, TRepr],
rem: Remover.Aux[TRepr, k.T, (V, TargetRepr)],
upd: Updater.Aux[TargetRepr, FieldType[k.T, V], H],
ali: Align[H, TRepr]
): SemiGeneric.Aux[T, TargetRepr] = new SemiGeneric[T] {
type Repr = TargetRepr
def convert: TargetRepr = gen.to(t) - k
}
}
I want to replace single k: Witness
with HList
of Witness
s. But even adding a generic Witness
type parameter cause the compilation error: can't find implicit value for Remover
.
implicit class SemiGenericIgnoringOps[T](t: T) {
def ignoring[TRepr <: HList,
V,
TargetRepr <: HList,
H <: HList,
W <: Witness](w: W) // added type parameter
(implicit
gen: LabelledGeneric.Aux[T, TRepr],
rem: Remover.Aux[TRepr, w.T, (V, TargetRepr)],
upd: Updater.Aux[TargetRepr, FieldType[w.T, V], H],
ali: Align[H, TRepr]
): SemiGeneric.Aux[T, TargetRepr] = new SemiGeneric[T] {
type Repr = TargetRepr
def convert: TargetRepr = gen.to(t) - w
}
}
It seems that compilator can't derive Witness.T
. Trick with Witness.Aux[R]
doesn't help. How to overcome this problem?
On contrary to the answer you referred to, you don't need
Updater
andAlign
since yourconvert
works withHList
/ record.The following code works: