score:4

Accepted answer

Shapeless tries to remove precisely type b.type but can't find it among Container["A"] :: Container["B"] :: Container["C"] :: HNil so @user is correct, singleton type b.type is too specific.

In order to infer an HList type from a val singleton type try to modify the method

implicit class RemoveAllOps[L <: HList](a: L) {
  def removeAll[L1 <: HList](b: L1)(implicit
    ra: shapeless.ops.hlist.RemoveAll[L, L1]
  ): ra.Out = ra(a)
}

a.removeAll(b) // (Container(B) :: Container(C) :: HNil,Container(A) :: HNil)

or

implicit class RemoveAllOps[L <: HList](a: L) {
  def removeAllFrom[O <: Singleton] = new {
    def apply[L1 >: O <: HList]()(implicit
      ra: shapeless.ops.hlist.RemoveAll[L, L1]
    ): ra.Out = ra(a)
  }
}

a.removeAllFrom[b.type]() //(Container(B) :: Container(C) :: HNil,Container(A) :: HNil)

Related Query

More Query from same tag