blob: 64b6270b74af03c41b1f6a61ae89d93b7f719e34 (
plain) (
tree)
|
|
import scala.reflect.macros.blackbox.Context
import language.experimental.macros
object Extractor {
def unapply(x: Int): Any = macro Macros.unapplyImpl
}
object Macros {
def unapplyImpl(c: Context)(x: c.Tree) = {
import c.universe._
q"""
new {
class Match(x: Int) {
def isEmpty = false
def get = x
}
def unapply(x: Int) = new Match(x)
}.unapply($x)
"""
}
}
|