Skip to content

Instantly share code, notes, and snippets.

@wheaties
Last active August 29, 2015 14:08
Show Gist options
  • Save wheaties/ad27362732d73697d9bb to your computer and use it in GitHub Desktop.
Save wheaties/ad27362732d73697d9bb to your computer and use it in GitHub Desktop.
Type Level Booleans
sealed trait Boolean{
def value: bool
}
case object True extends Boolean{
val value = true
}
case object False extends Boolean{
val value = false
}
trait Or[X <: Boolean, Y <: Boolean]{
type Out <: Boolean
def value: bool
}
object Or extends LowPriorityOr{
def apply[X <: Boolean, Y <: Boolean](implicit or: Or[X, Y]): Aux[X, Y, or.Out] = or
implicit object OrFalse extends Or[False, False]{
type Out = False
val value = false
}
}
trait LowPriorityOr{
implicit OrTrue[X <: Boolean, Y <: Boolean] = new Or[X, Y]{
type Out = True
val value = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment