mardi 21 avril 2015

How can I hide my implicit method or disable `LabelledGeneric` for a specific sealed family?

I have to use third-party traits which are designed as:

trait Super[T]
trait Sub[T] extends Sub[T]

and I have defined the following method to provide instances for arbitrary sealed families:

implicit def subFor[T, Repr](
  implicit
  gen: LabelledGeneric.Aux[T, Repr],
  sg: Lazy[JsonFormat[Repr]]
): Sub[T] = ???

but somewhere else in the code, somebody has already defined

implicit def superFor[T]: Super[T] = ???

for some specific types, e.g. Option and a few others.

Actually, I'd like to use the existing implementations instead of using my subFor generic implementation. However, because my method returns Sub[T] and the existing implementation returns Super[T] I can't see any way to define my implementation in such a way that it is considered lower priority.

How can I block my subFor from being called for specific types? Is there some way to disable LabelledGeneric for specific types, or some priority reducing mechanism that would stop the compiler from ever looking for my subFor if it already sees a Super[T]?

Aucun commentaire:

Enregistrer un commentaire