WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Scala - Closures


A closure is a function, whose return value depends on the value of one or more variables declared outside this function.

Example

object Demo {
    def main(args: Array[String]) {
        println( "add(1) value = " +  add(1) )
        println( "add(2) value = " +  add(2) )
    }
    var factor = 3
    val add = (i:Int) => i * factor
}
Output add(1) value = 3 add(2) value = 6