scala - What's the advantage of using multiple lists of function parameters? -
scala> def a(i:int)(j:int) = * j a: (i: int)(j: int)int scala> def b(i:int, j:int) = * j b: (i: int, j: int)int
the 2 definitions similar, , (appear me) same thing.
apart defining function receives implicit parameters or code block parameter, there reason use first definition style?
the main reason "currying" functions in manner enable partial application:
scala> val c = a(5) _ c: int => int = <function1>
here c function takes single int , returns result of multiplying int 5. may set c in 1 method, , pass method expects function taking 1 int parameter. bit trivial in case, flexible range of uses.
Comments
Post a Comment