I previously created a “SessionManagement” library. It defines some implicit extensions that allow me to do fun things like:
`
.debug.valueOf( SOME_SESSION_VARIABLE )
`
The only challenge is, it must not be the first element in the chain (for obvious reasons). I can work around it like this:
`
.during( Test.duration ) {
exec().debug.out( “my debug string” )
…
}
`
But what I would really like to be able to do is leave out the exec() part. I thought all I had to do was declare an object with an apply method, like so:
`
object debug {
def apply = exec().debug
}
`
But that doesn’t work. The compiler complains that the subsequent method (e.g. valueOf) is not a member of the “debug” object. Below are the relevant parts of my code.
`
object SessionManagement {
implicit class SessionManagementExtensions[T <: StructureBuilder[T]]( val c : T ) {
// …
trait _DEBUG {
def out( value : Any ) : T
def expr( value : Expression[Any] ) : T
def valueOf( name : SessionVariable ) : T
}
class consoleLogger extends _DEBUG { … }
def console = new consoleLogger
class debugLogger extends _DEBUG with StrictLogging { … }
def debug = new debugLogger
}
}
object console {
def apply = exec().console
}
object debug {
def apply = exec().debug
}
`
I was able to make it work by doing this:
`
object console {
def out( value : Any ) = exec().console.out( value )
def expr( value : Expression[Any] ) = exec().console.expr( value )
def valueOf( value : SessionVariable ) = exec().console.valueOf( value )
}
`
But it seems like I should be able to just delegate to the console object, like I originally tried to. Any ideas why that didn’t work?