When working with existing libraries (can't edit constructors or companion objects) I often find that I need to call an init/setup procedure on an object and then return the object itself. I usually end up doing something like the following.
def createObject: MyObject = {
val o = new MyObject
o.init()
o
}
This is IMHO not very elegant and I'm wondering if there's a better way of doing this, e.g., a setup-and-get function along the lines of:
def createObject: MyObject = {
setupAndGet(new MyObject) { _.init(v) }
}
Are there any existing solutions to this in Scala (besides writing my own)?