Having two simple classes taking Int as an argument:
case class Foo(i: Int)
class Bar(j: Int)
I can say:
List(1,2,3) map Foo
Which works fine and is equivalent to a bit more verbose:
List(1,2,3) map {Foo(_)}
However Bar (because it is not a case class?) cannot be used in the same construct:
List(1,2,3) map Bar
error: not found: value Bar
List(1,2,3) map Bar
^
Is there some special syntax to reference any constructor and take advantage of eta expansion? List(1,2,3) map {new Bar(_)} seems a bit more verbose compared to Foo.
It works in the former case, because companion object of a case class extends appropriate
FunctionNtrait. (object Foo extends (Int => Foo)in your example.) For non-case classes, you could do this manually:IMO it’s better to go with
new Bar(_)as this extra boilerplate might not be worth the little concision achieved.