I have been using currying with scala for literally years, but recently had reason to write a class constructor that is sort of a builder, where I don't want c and d to be optionals, so I don't want the class to be instantiated until they are available.
If I define my class thusly: MyClass(a: Int, b: Int)(c: String)(d: Long)
This compiles fine, but when I try to instantiate it like so:
val myConstructor = MyClass(a, b)(_)(_) //this is the only notation that works
the compiler thinks myConstructor is a (String, Long) => MyClass instead of a String => Long => MyClass
and I can't call myConstructor(someString) to get a Long => MyClass
Surely this is possible, but not finding how to instantiate it in a way the compiler likes.
Is this event possible with constructor?
Thanks!
Actually, the problem was that I had not defined
MyClassas a case class. It works as expected for case classes.