Scala Tips: Functions and Closures
In the Scala functions are first class. For example function literal can be possible to assign to object as follows: val f = (x:Int ) => x + x //f: Int => Int = <function1> f(2) // res0: Int = 4 The different between function literal and function value is that literal exists in source code and the value exists in the runtime. Compiler do the target typing if you don't specify the type for the x in the above source. To more precise, you can use the _ as a placeholder instead of x bound variable in the above code because x is a parameter to the function. For simplicity : //collection supports val l1 = for (i <- 1 to 10) yield i //l1: scala.collection.immutable.IndexedSeq[Int] = Vector(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) l1.filter(_ > 3 ) //res1: scala.collection.immutable.IndexedSeq[Int] = Vector(4, 5, 6, 7, 8, 9, 10) In the above source, when _ used that is called partially applied function because don't supply all of the arguments needed by the expre...