Allows to ignore some implicits in a LowPriority[T].
Use like LowPriority[Ignoring[Witness."ignoredMethod".T, T]].
Typical usage is when a fallback for type class TC is defined in its companion, like
object TC {
implicitdef anyTC[T]: TC[T] = ...
}
With the example of LowPriority[T] above,
trait TC[T] {
def prop: Option[Boolean]
}
trait LowPriTC {
// default low priority TC[T] for any T, with field `prop` equal to `None`implicitdef anyTC[T]: TC[T] = new TC[T] { def prop = None }
}
object TC extends LowPriTC {
// TC[Int] available by default, with field `prop` equal to `Some(true)`implicitval intTC: TC[Int] = new TC[Int] { def prop = Some(true) }
}
// extra `TC[T]`, with field `prop` equal to `Some(false)`implicitdef extraTC[T](implicit ev: LowPriority[Ignoring[Witness.`"anyTC"`.T, TC[T]]]): TC[T] =
new TC[T] { def prop = Some(false) }
// Already available instance `intTC` is still found, because `extraTC[Int]` requires a// `LowPriority[TC[Int]]`, that will refuse to materialize (because `LowPriority` is able to// know about the already available `intTC`.)
assert(implicitly[TC[Int]].prop == true)
// `extraTC[String]` is found, as the default `anyTC[String]` is ignored,
assert(implicitly[TC[String]].prop == false)
Allows to ignore some implicits in a
LowPriority[T].Use like
.T, T]]LowPriority[Ignoring[Witness."ignoredMethod".Typical usage is when a fallback for type class
TCis defined in its companion, likeWith the example of
LowPriority[T]above,