In old rusty Pascal, there was a convenient design for performing a sequence of actions on an object or record:
with obj do
begin
methodCall
otherMethodCall
...
end
I am trying to touch something similar in scala, but something is missing in my head :)
Is it possible in some way to achieve such an effect as if obj was in the current area of the passed closure and behaved like this:
{
import obj._
callObjMethod(x, y)
objVal.doSomething()
...
}
But in custom syntax, for example:
doWith (obj) {
callObjMethod(x, y)
objVal.doSomething()
}
Intuitively, I feel it is more nothan yesthat, but curiosity wants to know for sure.
source
share