Created
March 23, 2017 14:16
-
-
Save zainab-ali/9a761fb6418ad693f74606d085a801e3 to your computer and use it in GitHub Desktop.
or and refute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Refute[A] | |
object Refute { | |
implicit def ambiguous1[A](implicit ev: A): Refute[A] = new Refute[A] {} | |
implicit def ambiguous2[A](implicit ev: A): Refute[A] = new Refute[A] {} | |
implicit def refute[A]: Refute[A] = new Refute[A] {} | |
} | |
object TestRefute { | |
trait Foo | |
implicitly[Refute[Foo]] | |
} | |
trait Or[A, B] | |
object Or { | |
implicit def aAndB[A, B](implicit ev0: A, ev1: B): Or[A, B] = new Or[A, B] {} | |
implicit def aNotB[A, B](implicit ev0: A, ev1: Refute[B]): Or[A, B] = new Or[A, B] {} | |
implicit def bNotA[A, B](implicit ev0: B, ev1: Refute[A]): Or[A, B] = new Or[A, B] {} | |
} | |
object TestOr { | |
trait Foo | |
trait Bar | |
object BothPresent { | |
implicit val foo: Foo = new Foo {} | |
implicit val bar: Bar = new Bar {} | |
implicitly[Or[Foo, Bar]] | |
} | |
object NoFoo { | |
implicit val bar: Bar = new Bar {} | |
implicitly[Or[Foo, Bar]] | |
} | |
object NoBar { | |
implicit val foo: Foo = new Foo {} | |
implicitly[Or[Foo, Bar]] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment