In Scala, I can create a method that takes more than one argument list:
def myMethod(value: Int)(fn: (Int) => Unit) {
fn(value)
}
and call it like this:
myMethod(10) { value => println(value) }
How can I do the same thing with a class constructor? How do I call it?
This works.
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Client VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class MyClass(val value: Int)(val fn: Int => Unit)
defined class MyClass
scala> new MyClass(10)({value => println(value)})
res0: MyClass = MyClass@17577f9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With