Scala : Currying and Partial Functions
In the below example , user need not pass all arguements to the function at the same time. It is easier to pass around a function as a first-class object. You can keep applying parameters when you find them.Syntax:
def func_name(arg1:Type)(arg2:Type) .....
Eg:
object curry {
def add(a:Int)(b:Int){println(a+b)}
def main(args: Array[String]): Unit = {
val obj=this.add(10)(_)println(obj)
obj(20) }
}
result:
<function1> 30
result:
<function1> 30
No comments:
Post a Comment