Reputation: 170899
I want to do something like this:
trait Endo {
def apply[T](x: T): T
}
trait SuperType {
def endoMap(f: Endo): SuperType = macro SuperTypeMacro.endoMapImpl
}
case class Foo(x: Int) extends SuperType {
// endoMapImpl expands to
// Foo(f(x))
}
case class Bar(x: Int, y: Boolean) extends SuperType {
// endoMapImpl expands to
// Bar(f(x), f(y))
}
Ideally the only thing I would need to write is extends SuperType
. Is it possible? If not, I believe macro annotations should allow this; am I right?
Upvotes: 2
Views: 165
Reputation: 13048
I think what you're looking for is c.prefix
, that contains the receiver of the current macro method call. Once you get hold of it, you can branch on its type.
Upvotes: 2