Posts

Showing posts from December, 2018

Scala Functions

Local Functions Local functions are the functions defined inside other functions. Therefore , local functions can access the parameters of their enclosing function. First-class Functions Scala supports first-class functions which can be user defined as well as anonymous literal value, for example (x:Int) => x + 1 parameters and the function body separated by the "=>". In case if the type can be inference, then no need to define type, this is called target typing . In the partially applied function , no need to provide all the necessary parameters, but partially. For example, def sum(a:Int, b:Int):Int = a + b //> sum: (a: Int, b: Int)Int val a = sum _ //> a : (Int, Int) => Int = ex3$$$Lambd a.apply(1,2) //> res1: Int = 3 In the second line, you don't need to give parameters. The underscore can be given to replace one or more parameters: val f: (Int, I