From reading the blog post, I see more or less how to define what seems syntactically and semantically equivalent to adding a method to a class I don’t own. I.e., if class
Foo is defined elsewhere and
f is an instance of
Foo, then I can use a type class to define semantics for
My next question is whether this is limited to the left hand side of the dot? Can I also use a type class to define a binary function such as the following works?
def Foo(a:Int, b:MyClass):MyClass = ... def Foo(b:MyClass, a:Int): MyClass = ... def Foo(a1:Int, a2:Int): MyClass = ... def Foo(b1:MyClass,b2:MyClass): MyClass = ...
such that the following works?
List(1, MyClass(2), 3, MyClass(4), 5, 6).fold(MyClass(0))(Foo)
Or similarly, could I define a var-args version of
Foo which I could call as follows: