In Scala, if I define a method called apply
in a class or a top-level object, that method will be called whenever I append a pair a parentheses to an instance o
It is actually the other way around, an object or class with an apply method is the normal case and a function is way to construct implicitly an object of the same name with an apply method. Actually every function you define is an subobject of the Functionn trait (n is the number of arguments).
Refer to section 6.6:Function Applications of the Scala Language Specification for more information of the topic.