I'm totally new with Scala, I have to maintain an old code, so I have to understand what it does.
Now I am stuck on this piece of code, it is about defining and calling a method.
This is the definition of the method:
private def myMethod[I, O](price: Long, id: Int)(i: I)(f: (I, String) => O): O = {
..some code..
}
this is the method call
myMethod(price, id)(b) {
..some code.. //single line of code, just calling an other function
}
I understood the part of having type parameter also of having multiple parameter (currying).
But what I didn't understand, is :
- first of all this part:
(f: (I, String) => O)
, this is completely strange for me - second, why in the method call, it contains code after the
{
symbol, is it overriding the original method? even it's the case, it make no sense to override it when making the call - also,
myMethod
is supposed to return a value of typeO
, but in my code it's never affected to any variable. (EDIT: this point is clear now, I just misunderstood the code, nvm mind about it)
Please can any one clarify this points (especially the first and second one which are making me so confused)
EDIT
private var x : classX
myMethod(price, id)(b) {
x.listX //calling method without parameters
}
def listX (param1: ListFaFBI, param2: String): ListX ={
//returning an Object of type ListX, not a function
}
as you can see that myMethod
is calling listX
. if I understood well, myMethod
is returning the method listX
itself which has two parameters ListFaFBI
(or I
) and String
and returning ListX
(or O
) as defined in (f: (I, String) => O)