Let’s say I have function:
def foo[A,B](a : A, f : A => B) = ...
And I call it:
var x = new X()
foo(x, obj => ...
At this point it is clear that type of argument of lambda (obj here) is X (C# works that way for example).
However in Scala I have to write:
foo(x, (obj : X) => ...
It causes a lot of noise in code.
Question
How to write my function foo to avoid such over-specification on every call? Or maybe I am missing something and adding type is needed because such call (without type info) would be ambiguous.
I think currying in general is the way to go, but if you have lots of functions with the same type of argument you could do something like this: