When defining a case class, the default companion object has nice curried
method to get a curried version of the case class constructor:
scala> case class Foo(a: String, b: Int)
defined class Foo
scala> Foo.curried
res4: String => (Int => Foo) = <function1>
However, as soon as I define an explicit companion object, this method disappears:
scala> :paste
// Entering paste mode (ctrl-D to finish)
case class Foo(a: String, b: Int)
object Foo {}
// Exiting paste mode, now interpreting.
defined class Foo
defined module Foo
scala> Foo.curried
<console>:9: error: value curried is not a member of object Foo
Foo.curried
I can get it back like so:
scala> :paste
// Entering paste mode (ctrl-D to finish)
case class Foo(a: String, b: Int)
object Foo { def curried = (Foo.apply _).curried }
// Exiting paste mode, now interpreting.
defined class Foo
defined module Foo
scala> Foo.curried
res5: String => (Int => Foo) = <function1>
However, I'd like to know why it disappears when defining an explicit companion (eg. in contrast to apply
)?
(Scala 2.9.2)
(Foo(_,_)).curried
has the same effect – SuboceanicScala 2.10.0-M7
behaves the same. – Acrilan(Foo.apply _).curried
gets it. – Maccaboy