Skip to content

Instantly share code, notes, and snippets.

@runarorama
Last active December 10, 2015 21:38
Show Gist options
  • Save runarorama/4496636 to your computer and use it in GitHub Desktop.
Save runarorama/4496636 to your computer and use it in GitHub Desktop.
trait True
trait False
def impl(c: Context)(nExpr: c.Expr[Int]): c.Tree = {
import c.universe._
val n: Int = c.eval(c.Expr[Int](c.resetAllAttrs(nExpr.tree)))
if (n >= 3) tq"True" else tq"False"
}
type AtLeastThree(i: Int) = macro impl
val x: AtLeastThree(4) = new True
val y: AtLeastThree(1) = new False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment