As a little thoughtful exercise, I wonder if it is possible to make a scala trait that does a deep search in the current object for other elements that meet this definition and call them. For instance:
trait CanDebug { this => def depthFirstDebug(level:Int) { for ( x<-(this object search matching type CanDebug)) { x.depthFirstDebug(level+1) } println("level "+level+" "+this.toString) } } case class A (s:String) extends CanDebug class B extends CanDebug { val a1 = A("Hello")
Put something into action:
Level 1 Hello World Level 1
Level 0 Start
Using scala 2.10.2, and I believe that this should be possible using reflection, but I'm not sure about the logistics. thank you
source share