Created
March 9, 2022 02:56
-
-
Save tarao/853248d8be6fad527693c0d58e0353d6 to your computer and use it in GitHub Desktop.
This file contains 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
import scala.compiletime.ops.{any, int} | |
trait Odd | |
object Odd { | |
type IsOdd[I <: Int] = any.!=[int.%[I, 2], 0] | |
def apply[I <: Int](i: I)(using IsOdd[I] =:= true): Int & Odd = | |
i.asInstanceOf[Int & Odd] | |
} | |
trait Even | |
object Even { | |
type IsEven[I <: Int] = any.==[int.%[I, 2], 0] | |
def apply[I <: Int](i: I)(using IsEven[I] =:= true): Int & Even = | |
i.asInstanceOf[Int & Even] | |
} | |
val i1 = Odd[1] | |
// val i2 = Odd[2] // compile error | |
// val i3 = Even[3] // compile error | |
val i4 = Even[4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment