Created
April 3, 2015 01:06
-
-
Save mpilquist/d4d24e6bf45d1f4f2b8e to your computer and use it in GitHub Desktop.
Non-working macro for scoping implicits
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
def local[A](implicits: Any*)(f: => A): A = macro localMacro[A] | |
def localMacro[A](c: Context)(implicits: c.Expr[Any]*)(f: c.Expr[A]): c.Expr[A] = { | |
import c.universe._ | |
val implicitVals = implicits.map { imp => | |
val name = TermName(c.freshName()) | |
q"implicit val $name = $imp" | |
} | |
c.Expr[A](q"{ ..$implicitVals; $f }") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discussion: https://twitter.com/mpilquist/status/583798342565634048. Please leave comments there, because gists don't support notifications, and we will most likely be unable to respond to you here.